Lets say I have this sample data file
1 2
2 3
3 4
1 5
2 6
3 7
1 8
2 9
3 10
Now in gnuplot if I run this command
pl 'test.dat' u 1:2 every :::0::2 w l
It plots three lines for each of the block in the data file, but there's no way to distinguish which line comes from which data block. I want those three lines to have three different colors and different legend labels. Can I do that in addition to the every command?
Sure, there are multiple ways to achieve that. If you insist on having a single empty line between the blocks and on using
every, you can plot iteratively:plot for [i=0:*] 'test.dat' u 1:2 every :::i::i w l lc iAlternatively, if you separate your data block with two empty lines, you can use the index:
plot for [i=0:*] 'test.dat' index i u 1:2 w l lc i(shortcuti iinstead ofindex iis also allowed, but difficult to read)Or without iteration, but using the pseudo-column -2 (which gives you the index number). Note that gnuplot doesn't draw continuous lines between points that are separated with empty lines, therefore the
everycommand is not necessary.plot 'test.dat' u 1:2:-2 w l lc variableAutomatically generated, different labels can be produced in the following way:
plot for [i=0:*] 'test.dat' i i u 1:2 w l lc i t sprintf('This is block %d', i)