Many datasets in gnuplot: difference in index behavior with iteration and range

I think I understand from the behavior how these two plot commands are different, but I really don't understand why they are different. That is, I did not expect that there would be a difference. These two cases:

plot for [i=0:3] 'ctg-y2.dat' index i using 2 title columnheader(2) with lines 

and

 plot 'ctg-y2.dat' index 0:3 using 2 title columnheader(2) with lines 

(example data file http://gnuplot.cvs.sourceforge.net/viewvc/gnuplot/gnuplot/demo/ctg-y2.dat )

The first one does what I expect: for each of the four data sets in the file, read the column header from the first row of the data set and build the remaining data. The second does something completely different: it does not read the column heading for any data set, but the first, and it seems that it displays all the data as if they were part of a single data set. The result is a mess, since the implicit x values ​​do not match correctly.

The index description in the manual does not mention this use of the range with the index, as far as I can tell. Is this documented somewhere? This is mistake? Am I doing something stupid?

+4
source share
1 answer

I have never used index before, but if I understand it correctly, it seems to combine all indexed datasets into one set. This is why all lines appear in red. However, if constructed with respect to the column index, and not at the specified index (for example, using 2 vs using 1:2 ), it seems to return to index 1. This is because the first row cannot be interpreted (because she is the name).
The column heading issue seems to work fine, since gnuplot expects to have only one dataset that matches the index keyword and therefore does not expect to have multiple column headers.

Since you have already solved your problem with iterations, there is no need for additional sentences. I think this is exactly how you should build your data.

+2
source

All Articles