user2138149
user2138149

Reputation: 17140

GNUPlot: Plot each data block on new graph ("for each datablock")

I have a file which I am plotting with gnuplot. My data looks like this:

x,y1,y2
0,0,0
1,0.0,0.1
1,0.1,0.15
1,0.3,0.2
    ... etc

              2 blank lines -> new block

0,0,0
0,0,0        (just example data)
0,0,0
    ... etc


              2 blank lines -> new block
0,0,0
0,0,0
0,0,0
    ... etc

        ... etc    (more blocks)

If I run the command: plot 'file.csv' using 1:2, then all the blocks appear on the same graph. I have about 1000 blocks, so obviously this produces something unreadable.

How can I plot all the blocks on different graphs? Sort of like a "for each datablock" loop or something?

Possible Partial Answer

I have made progress on this using a gnuplot for loop. This might not actually be a particularly good method, and I am now stuck as I am unable to count the number of "data blocks" in my file.

This is what I have so far:

NMAX=3 # How do I know what this should be?
 
do for [n=0:NMAX] {
   ofname=sprintf("%d.png", n)
   set output ofname
   plot 'timeseries.csv' index n using 1:2, 'timeseries.csv' index n using 1:3 with lines
}

Perhaps that is useful? At the moment I don't know how to set NMAX automatically.

Further Developments

NMAX can be set using the stats command: stats 'datafile.csv' then NMAX=STATS_blocks.

There may be a better method.

Upvotes: 0

Views: 1414

Answers (1)

user2138149
user2138149

Reputation: 17140

This question helped me: Count number of blocks in datafile

My code:

stats datafile
NMAX=STATS_blocks

do for [n=0:NMAX] {
    ofname=sprintf("%d.png", n)
    set output ofname
    plot 'timeseries.csv' index n using 1:2, 'timeseries.csv' index n using 1:3 with lines
}

Upvotes: 1

Related Questions