23
votes

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.

4
How did you get this Gnuplot GUI? What command launches this window? - Jeef
@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. - Léo Léopold Hertz 준영
Thanks - this was so long ago i forgot what i even was doing! :) - Jeef

4 Answers

29
votes

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
11
votes

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.

7
votes

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.

1
votes

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

set datafile separator "\t"