28

I have the following dat file, named ls.dat:

# Gnuplot script file for "ls"
# Version       Removed Added   Modified
8.1     0       0       0
8.4     0       0       4
8.5     2       5       9
8.6     2       7       51
8.7     2       7       51
8.8     2       7       51
8.9     2       7       51
8.10    2       7       51
8.11    2       8       112
8.12    2       8       112
8.13    2       17      175
8.17    6       33      213

I am trying to plot with this:

plot "ls.dat" using 1:2 title 'Removed' with lines,\
     "ls.dat" using 1:3 title 'Added' with lines,\
     "ls.dat" using 1:4 title 'Modified' with lines

This produces the following graph:

enter image description here

What I am expecting is three line plots which should all go up, but at different rates. Can anyone see what is going on here? I'm sure it must be something very silly.

3
  • 1
    How did you get this Gnuplot GUI? What command launches this window?
    – Jeef
    Mar 21, 2014 at 15:13
  • 3
    @Jeef Its gnuplot-X11 in OSX. You can also use gnuplot in Qt. It depends where is your terminal type set to what you get. Mine is gnuplot-qt. Mar 25, 2015 at 20:13
  • 1
    Thanks - this was so long ago i forgot what i even was doing! :)
    – Jeef
    Mar 26, 2015 at 0:58

4 Answers 4

33

I think your problem is your version numbers. Try making 8.1 --> 8.01, and so forth. That should put the points in the right order.

Alternatively, you could plot using X, where X is the column number you want, instead of using 1:X. That will plot those values on the y axis and integers on the x axis. Try:

plot "ls.dat" using 2 title 'Removed' with lines, \
     "ls.dat" using 3 title 'Added' with lines, \
     "ls.dat" using 4 title 'Modified' with lines
3
  • You may also want a log scale on the y axis (using set log y) since your numbers span such a range.
    – andyras
    May 29, 2012 at 1:48
  • Good point on the using X -- I think that you could also use using X:xtic(1) to keep your xtics the version number that you want, though I haven't tried it...(+1)
    – mgilson
    May 29, 2012 at 2:11
  • 2
    Also, andyras, you're putting a real damper on my quest to get the bronze gnuplot badge by answering all these questions before I get a chance to see them ;) .
    – mgilson
    May 29, 2012 at 2:16
11

andyras is completely correct. One minor addition, try this (for example)

plot 'ls.dat' using 4:xtic(1)

This will keep your datafile in the correct order, but also preserve your version tic labels on the x-axis.

0
8

In addition to the answers above the command below will also work. I post it because it makes more sense to me. In each case it is 'using x-value-column: y-value-column'

plot 'ls.dat' using 1:2, 'ls.dat' using 1:3, 'ls.dat' using 1:4 

note that the command above assumes that you have a file named ls.dat with tab separated columns of data where column 1 is x, column 2 is y1, column 3 is y2 and column 4 is y3.

Edit for .csv file types....

Note if you have a .csv file then if you use the gnuplot command

set datafile separator comma

you can then use the plot command above for data files where the numbers are separated by commas.

2
  • Hi, tom. What's the version of your gnuplot?
    – Scott Yang
    Mar 27, 2019 at 15:05
  • @ScottYang when I wrote the answer the version might have been 4.2, but I am really not sure to be honest. I think any version of Gnuplot should work with the command above as I think it has been pretty standard for a while. I just used it to plot a data file with Gnuplot 5.0n --- plus note that I have put an edit in the answer as well to make it clearer.
    – tom
    Mar 29, 2019 at 15:20
1

Whatever your separator is in your ls.dat, you can specify it to gnuplot:

set datafile separator "\t"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.