4

so I want to plot from a data file which has an undetermined number of fields of x and y data (of unknown but constant length). I want to plot them all together on one graph, BUT with different colors.

Without specifying the index, they all plot together with the same color.

Using a for-loop on the index or writing the indicies individually DOES plot them together with different colors, BUT the program will not know how many indicies to loop over.

Setting a really high number for the max of the for-loop works, but makes error messages when it runs out of data.

Is there any way to manipulate the data in gnuplot to derive the number of indices for the for-loop?

andyras
  • 15,542
  • 6
  • 55
  • 77
Stershic
  • 191
  • 4
  • 13
  • I think I can answer your question, but a little more information would be helpful. Which version of gnuplot are you using? It would also help if you could post some example code/data that you are using. – andyras Feb 12 '13 at 04:24

1 Answers1

5

If you have gnuplot >= 4.6.0, you can use the stats command:

#!/usr/bin/env gnuplot

reset

datafile = 'data.dat'

set terminal png size 600,400
set output 'test.png'

stats datafile

plot for [i=1:STATS_blocks] datafile index (i-1) pt 7 ps 2 title 'record '.i

If your data looks like this (with two blank lines separating the data blocks)

1 1


2 2


3 3


4 2


0 3

That script will make this plot:

enter image description here

The same should apply for blocks of data with more than one (x,y) pair.

andyras
  • 15,542
  • 6
  • 55
  • 77
  • Records didn't work (that gave the total number of lines I think -- its the same in your example), but `STATS_blocks` did. Thanks for steering me that direction! I spent two hours searching the internet for solutions yesterday and didn't come across this stats tool -- very useful! – Stershic Feb 12 '13 at 19:43
  • You are absolutely right, I should have used `STATS_blocks`. I updated my answer accordingly. – andyras Feb 13 '13 at 15:38