1
votes

I have text files containing two columns of numbers which I'll call col1 and col2. I'm able to use gnuplot to plot col2 versus col1 or vice-versa but I can't figure out how to plot both col1 and col2 (i.e., overlay both columns of data) as a function of the row number in the file (i.e., the x axis is given implicitly by the file row numbering). I suppose I could insert a row number into column one but I'm guessing there is an easier way to do this in gnuplot. In linux I could use "cat -n" to output a three column file but I'm trying to do this on a Windows system for a friend and I don't know if Windows has something akin to cat.

Thank you!

2

2 Answers

2
votes

Use column index 0 for the line number:

plot "file" using 0:1, "" using 0:2
1
votes

Just for the records. Whatever you consider as line number... In most cases the pseudocolumn 0 (check help pseudocolumns) will do the job. However, if you have double empty lines in your data the situation will look different, because the pseudocolumn 0 will be reset to 0. Check the following example to illustrate the difference between pseudocolumn 0 and another approach counting the lines yourself.

Code:

### plotting data versus "line number"
reset session

$Data <<EOD
 1   21
 2   22
 3   23

 5   24
 6   25
 7   26


10   27
11   28
12   29
EOD

set multiplot layout 1,2

    plot $Data u 0:2 w lp pt 7

    plot n=0 $Data u (n=n+1):2 w lp pt 7

unset multiplot
### end of code

Result:

enter image description here