Donnerstag, 23. Oktober 2014

gnuplot loop over all blocks in datafile

If you have a data file for gnuplot with indexable blocks (two blank lines between data blocks) e.g.:

0 1
1 2

0 1.5
1 2.5


0 2.0
2 3.0

and want to plot each plot individually but with the same plot command, you can simply use the gnuplot 4.6 stats function to get the number of blocks and loop over the blocks in a combined command:

#!/usr/bin/gnuplot

file="data.dat"
stats file

plot for [i=0:STATS_blocks-2] file index i w l ls i+1
PS: if you only have one blank line between data blocks you need to use the every command:
#!/usr/bin/gnuplot

file="data.dat"
stats file

plot for [i=0:STATS_blank] file every :::i::i w l ls i+1

Keine Kommentare:

Kommentar veröffentlichen