Gnuplot Cannot Find or Open Your Data File? Fixes That Work

The file is right there in your folder — you can see it — yet gnuplot answers:

warning: Cannot find or open file "data.dat"
No data in plot

This is one of the most common gnuplot frustrations, and it is almost never about the file itself. It is about where gnuplot is looking.

What this message means

Gnuplot resolves relative filenames against its own current working directory — the directory the gnuplot process was started in — which is often not the folder containing your script or your data. Double-clicking a script, launching gnuplot from a desktop icon, or running it from an editor can each start it in a different directory. If the name does not resolve there, gnuplot reports that it cannot find or open the file.

Causes, most likely first

  1. Working directory mismatch. The classic case: gnuplot starts in your home directory, the data sits next to the script somewhere else.
  2. A filename typo or wrong extension. data.txt vs data.dat, or a file the editor saved as data.dat.txt with the real extension hidden.
  3. Windows paths with unescaped backslashes in a script. Inside double quotes, sequences like \n or \t in a path are interpreted as escapes, mangling the name.
  4. The file was never actually saved. The editor shows the data, but the unsaved buffer means the file on disk is old, empty, or absent.

Fixes, step by step

1. Ask gnuplot where it is standing

Run these two commands in the gnuplot session itself:

pwd
!ls

pwd prints gnuplot’s working directory and !ls (on Windows, !dir) lists what is actually in it. If your data file is not in that listing, gnuplot cannot open it by bare name — full stop.

2. Change directory from inside gnuplot

The cd command moves gnuplot’s working directory; scripts usually do this first so every relative name in the script works:

cd "C:/Users/you/Documents/plots"
# or on Linux/macOS:
cd "/home/you/plots"
plot "data.dat" using 1:2 with lines

3. Write Windows paths safely

Two reliable options: use forward slashes (Windows accepts them in gnuplot), or use single quotes so backslashes are not treated as escapes:

plot "C:/Users/you/Documents/plots/data.dat" using 1:2 with lines
plot 'C:\Users\you\Documents\plots\data.dat' using 1:2 with lines

What fails is the double-quoted path containing sequences like \n (from a folder named newdata, for example): "C:\newdata\data.dat" does not point where you think it does.

4. Rule out the unsaved-file trap

Save the file in your editor, then check its real name and size from a terminal: dir data* on Windows or ls -l data* elsewhere. A listing that shows data.dat.txt or a 0-byte data.dat is the whole diagnosis.

A minimal script that works

Put demo.dat and this script in the same folder, and start gnuplot from that folder:

# demo.dat:
# 1  2.0
# 2  3.5
# 3  3.1
reset
print "Working directory: ", GPVAL_PWD
set terminal pngcairo size 800,600
set output "demo.png"
plot "demo.dat" using 1:2 with linespoints
set output

If this runs, switch to your real filename and confirm with pwd which directory the working version was launched from — then either always launch from there, or add a cd line at the top of your script. If the file now opens but gnuplot complains there is nothing to plot, see the companion guide on the “no valid points” warning.

Still stuck?

The official documentation at gnuplot.info includes the full command reference, and the gnuplot-info mailing list linked there is the best place to ask when a script misbehaves in a way this page does not cover — include the exact error message and a small sample of your data when you post.

Related troubleshooting

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *