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.

Trygve Laugstøl
  • 7,440
  • 2
  • 36
  • 40
Mike Kwan
  • 24,123
  • 12
  • 63
  • 96

4 Answers4

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
sehe
  • 374,641
  • 47
  • 450
  • 633
andyras
  • 15,542
  • 6
  • 55
  • 77
  • 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 '12 at 01: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 '12 at 02: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 '12 at 02: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.

mgilson
  • 300,191
  • 65
  • 633
  • 696
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.

tom
  • 1,303
  • 10
  • 17
  • Hi, tom. What's the version of your gnuplot? – Scott Yang Mar 27 '19 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 '19 at 15:20
1

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

set datafile separator "\t"
kukinsula
  • 322
  • 4
  • 8