28

I'm trying to make a graph with gnuplot. I specified my xrange, yrange, and labels, but when I typed in the following command:

gnuplot> plot "data.txt" using 1:2 with lines

gnuplot tells me:

warning: Skipping unreadable file "data.txt" No data in plot.

I don't understand how my data file is unreadable. This is what my data.txt looks like:

X       Y  [I didn't enter X and Y into my text file]

10000   0.030
5000    0.02
1000    0.012

I know I must be doing something wrong -- this is my first time using gnuplot. I tried doing a Google search on how to make a proper data.txt file turns up zilch.


EDIT:

I feel like this may sound strange to ask at a programming Q&A site, but what should a typical text file w/data look like? I'm no computer programmer, just an undergrad trying to plot a graph for her biochemistry class.

David Nehme
  • 21,379
  • 8
  • 78
  • 117
Miriam
  • 393
  • 1
  • 3
  • 7

8 Answers8

21

Either as most people answered: the file doesn't exist / you're not specifying the path correctly.

Or, you're simply writing the syntax wrong (which you can't know unless you know what it should be like, right?, especially when in the "help" itself, it's wrong).

For gnuplot 4.6.0 on windows 7, terminal type set to windows

Make sure you specify the file's whole path to avoid looking for it where it's not (default seems to be "documents")

Make sure you use this syntax:

plot 'path\path\desireddatafile.txt'

NOT

plot "< path\path\desireddatafile.txt>"

NOR

plot "path\path\desireddatafile.txt"

also make sure your file is in the right format, like for .txt file format ANSI, not Unicode and such.

Ciro Santilli OurBigBook.com
  • 347,512
  • 102
  • 1,199
  • 985
Paul
  • 211
  • 2
  • 3
  • I freaking love you. Thank you. I was looking for the correct way to pass a path to gnuplot, for the correct way to let gnuplot find my file. – DanBeale Jul 23 '13 at 21:54
14
plot "data.txt" using 1:2 with lines 

works for me. Do you actually have blank lines in your data file? That will cause an empty plot. Can you see a plot without data? Like plot x*x. If not, then your terminal might not be set up correctly.

David Nehme
  • 21,379
  • 8
  • 78
  • 117
  • 1
    The way I typed up the text file is exactly how I have it in my post. I do see a plot---I plotted a sin(x) graph just to make sure gnuplot wasn't acting buggy and it came out just fine. – Miriam Sep 21 '11 at 02:38
  • Ok, so your gnuplot is able to produce plots. If you have blank lines in your data file, you will get an empty plot. Remove the blank lines and you should have your plot. – David Nehme Sep 21 '11 at 02:40
  • 1
    Although in the above post I added a the text contained within my text file, I actually do not have any blank spaces or any lines... it's just a really plain text file with nothing but numbers. – Miriam Sep 21 '11 at 03:15
  • what editor are you using to create the file? If you are running on windows, you should be able to do a type data.txt from the command line and just see the data. – David Nehme Sep 21 '11 at 03:23
  • I'm using a text editor with Gnome3, gedit. I'd post a snapshot, but there are some restrictions on this forum for uploading photos when you're a new user. Would gnuplot be able to read a LaTeX file? – Miriam Sep 21 '11 at 03:29
  • If you are on linux, you should be able to do a cat on the file and see its actual contents and make sure there are only numbers. – David Nehme Sep 21 '11 at 03:34
  • Okay, I'll try doing that. If I still run into this error, I'm just going to use Mathematica. Thanks for your help! – Miriam Sep 21 '11 at 03:38
7

Create your Datafile like this:

# X      Y
10000.0 0.01
100000.0 0.05
1000000.0 0.45

And plot it with

$ gnuplot -p -e "plot 'filename.dat'"

There is a good tutorial: http://www.gnuplotting.org/introduction/plotting-data/

Thomas
  • 2,127
  • 1
  • 32
  • 45
1

For future reference, I had the same problem

"warning: Skipping unreadable file"

under Linux. The reason was that I love using Tab-completing and in gnuplot this added a whitespace at the end that I did not really notice

gnuplot> plot "./datafile.txt "
henrikz
  • 43
  • 1
  • 6
1

I had the same issue when tried to open the file using Plot->Data filename... option provided in the version for Windows 7 (by the way, it worked fine on another computer with the same version of the OP system).

Then I tried to change directory and save the .plt file, but it didn't work either. Finally, I tried to tape manually as it was showed for Linux earlier in this queue of posts:

gnuplot > plot "./datafile.dat"

and it worked!

ByteHamster
  • 4,884
  • 9
  • 38
  • 53
0

I was having the exact same issue. The problem that I was having is that I hadn't saved the .plt file that I was typing into yet. The fix: I saved the .plt file in the same directory as the data that I was trying to plot and suddenly it worked! If they are in the same directory, you don't even need to specify a path, you can just put in the file name.

Below is exactly what was happening to me, and how I fixed it. The first line shows the problem we were both having. I saved in the second line, and the third line worked!

gnuplot> plot 'c:/Documents and Settings/User/Desktop/data.dat'
         warning: Skipping unreadable file c:/Documents and Settings/User/Desktop/data.dat
         No data in plot

gnuplot> save 'c:/Documents and Settings/User/Desktop/myfile.plt'

gnuplot> plot 'c:/Documents and Settings/User/Desktop/data.dat'
The Unfun Cat
  • 29,987
  • 31
  • 114
  • 156
Nathan
  • 9
  • 1
0

Just go to the properties of your cmd.exe shortcut and change the 'start in' by adding the file name where you put all your '.txt' files.I had same problems and i put the whole file mane as 'D:\photon' in the 'start in' of the properties and it worked.Remember you have to put all your files in that folder otherwise you have to create many shortcuts for each data files.Sorry for late reply

saayan
  • 1
0

This error usually means the file couldn't be found.

Can you see the file from the command line?

  1. Try specifying the full pathname.
  2. check line ending type (use 0x0d).
  3. is file open in another program?
  4. do you have read access to it?
Sanjay Manohar
  • 6,920
  • 3
  • 35
  • 58
  • Well, I do see that the file is in the directory I save it in when I view the directory via the terminal. Should I have the file open in the terminal before running gnuplot? Or is it completely independent of that? – Miriam Sep 21 '11 at 02:41
  • He gets the message 'skipping unreadable data in "data.txt" ' so it looks like gnuplot is able to read the file. – David Nehme Sep 21 '11 at 02:41