is there a for loop in gnuplot language?

is there a for loop in gnuplot language?

Post by Hicham Mou » Fri, 18 Jun 2010 23:11:46


I generate a data file as:
x,y,z
format.

and then I plot 2D projection in a multiplot by using size and origin and
plot and 'using'

I draw 8 plots per multiplot.

I'd like to automate the process. I can generate a batch file and run
gnuplot to load that file and run it.

Currently, I type 8 instructions:

set origin 0, 0; plot '...' using 2:($1==...? $3: 1/0)
set origin 0.25, 0;
set origin 0.5, 0
set origin 0.75, 0
set origin 0, 0.5
set origin 0.25, 0.5
set origin 0.5, 0.5
set origin 0.75, 0.5

regards,
 
 
 

is there a for loop in gnuplot language?

Post by Per Juh » Fri, 18 Jun 2010 23:51:58


If you want a tableau of sub-plots in a more or less regular grid,
then the "set multiplot layout" option is for you.
See its help page for syntax and usage tips. Chances are that it will
obviate the need for explicit set size; set origin commands. Those are
only needed if you want to have non-evenly sized subplots or small
insets in a large plot etc.
With the "layout" mode you just have to list your plot commands in the
desired sequence.

As for loops, see 'reread'. You could use that to achieve what you
want without explicitly listing all the plot commands, but I don't
think it's worth the hassle.

Unfortunately there are no generic for loops or other erm... advanced
flow control features.

Still, if you think that all those repetitive plot commands with only
one value changed between them are an eyesore - well, there is a way
in version 4.4+ to do it in a more elegant way (for some value of
"elegant"):

myplot(x) = sprintf("plot 'datafile' u 2:($1== %f ? $3 : 1/0)", x)

set multiplot layout 4,2
eval myplot(0)
eval myplot(1.5)
#...
eval myplot(pi)
unset multiplot

This is essentially dynamically generating the necessary plot commands
with the actual value-to-be-tested inserted each time.

Per Juhz

 
 
 

is there a for loop in gnuplot language?

Post by Dieter Bri » Sat, 19 Jun 2010 16:48:14


Must you type? If you set it up as a batch file or shell script, you
can use your editor to do the repeating.
--
Dieter Britz (dieterhansbritz<at>gmail.com)
 
 
 

is there a for loop in gnuplot language?

Post by Hicham Mou » Sat, 19 Jun 2010 21:01:53


Still, if you think that all those repetitive plot commands with only
one value changed between them are an eyesore - well, there is a way
in version 4.4+ to do it in a more elegant way (for some value of
"elegant"):

myplot(x) = sprintf("plot 'datafile' u 2:($1== %f ? $3 : 1/0)", x)

set multiplot layout 4,2
eval myplot(0)
eval myplot(1.5)
#...
eval myplot(pi)
unset multiplot

This is essentially dynamically generating the necessary plot commands
with the actual value-to-be-tested inserted each time.

Per Juhz
--------------------------------------------------------------------------------------------

The number of subplots is only know at runtime at the end of running a
program.
I wouldn't know how many times to call eval

Thanks,
 
 
 

is there a for loop in gnuplot language?

Post by adam majew » Mon, 21 Jun 2010 16:54:44

W dniu 2010-06-18 14:01, Hicham Mouline pisze:


Here is about loop in gnuplot :
http://www.yqcomputer.com/ #9.1

I do not know how to do it in gnuplot , but you can also use gnuplot
thru Maxima CAS.
http://www.yqcomputer.com/
http://www.yqcomputer.com/

Here in Maxima are more possibilities :

You can make a list of parameters and at the end of the program
draw using one command.

HTH

Adam
 
 
 

is there a for loop in gnuplot language?

Post by adam majew » Mon, 21 Jun 2010 17:50:49

W dniu 2010-06-20 09:54, adam majewski pisze:



Here is an example image , not multiplot but with dynamical creating of
plot command :
http://www.yqcomputer.com/ :Circle_7_4.svg

HTH

Adam