0

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.

0

1 Answer 1

1

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
}
Sign up to request clarification or add additional context in comments.

1 Comment

If this solved your problem, you can accept your own answer, indicating that your question is answered and it doesn't appear as open question.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.