Loop structure inside gnuplot?
Solution 1:
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.
Solution 2:
Take a look also to the do { ... }
command since gnuplot 4.6 as it is very powerful:
do for [t=0:50] {
outfile = sprintf('animation/bessel%03.0f.png',t)
set output outfile
splot u*sin(v),u*cos(v),bessel(u,t/50.0) w pm3d ls 1
}
http://www.gnuplotting.org/gnuplot-4-6-do/
Solution 3:
I have the script all.p
set ...
...
list=system('ls -1B *.dat')
plot for [file in list] file w l u 1:2 t file
Here the two last rows are literal, not heuristic. Then i run
$ gnuplot -p all.p
Change *.dat
to the file type you have, or add file types.
Next step: Add to ~/.bashrc this line
alias p='gnuplot -p ~/./all.p'
and put your file all.p
int your home directory and voila. You can plot all files in any directory by typing p and enter.
EDIT I changed the command, because it didn't work. Previously it contained list(i)=word(system(ls -1B *.dat),i)
.