Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Loop structure inside gnuplot?

Tags:

gnuplot

Is there any way to iteratively retrieve data from multiple files and plot them on the same graph in gnuplot. Suppose I have files like data1.txt, data2.txt......data1000.txt; each having the same number of columns. Now I could write something like-

plot "data1.txt" using 1:2 title "Flow 1", \      "data2.txt" using 1:2 title "Flow 2", \       .       .       .      "data1000.txt"  using 1:2 title "Flow 6" 

But this would be really inconvenient. I was wondering whether there is a way to loop through the plot part in gnuplot.

like image 480
Slayer Avatar asked Feb 18 '13 22:02

Slayer


1 Answers

There sure is (in gnuplot 4.4+):

plot for [i=1:1000] 'data'.i.'.txt' using 1:2 title 'Flow '.i 

The variable i can be interpreted as a variable or a string, so you could do something like

plot for [i=1:1000] 'data'.i.'.txt' using 1:($2+i) title 'Flow '.i 

if you want to have lines offset from each other.

Type help iteration at the gnuplot command line for more info.

Also be sure to see @DarioP's answer about the do for syntax; that gives you something closer to a traditional for loop.

like image 188
andyras Avatar answered Sep 21 '22 12:09

andyras