Variables in gnuplot commands

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Variables in gnuplot commands

Ronald Kumon
Does anyone know why you cannot use variables in gnuplot "set" commands
from within Octave?

For example, in gnuplot you can execute the commands:

gnuplot> xsize=0.5
gnuplot> ysize=0.5
gnuplot> set size xsize,ysize
gnuplot> show size

         size is scaled by 0.5,0.5
         no attempt to control aspect ratio

However, the corresponding commands in octave give:

octave> xsize=0.5
octave> ysize=0.5
octave> set size xsize,ysize
octave>          line 0: undefined variable: xsize

I have been able to do the equivalent via the "eval" command:

octave> xsize=num2str(0.5)
octave> ysize=num2str(0.5)
octave> eval(["set size ",xsize,",",ysize])
octave> show size

        size is scaled by 0.5,0.5
        no attempt to control aspect ratio

but this seems a little messy.

Interestingly enough, variable substitution does occur automatically
in the gplot command since

octave> ltnum=3
octave> gplot "data" using 1:3 with lines ltnum

will successfully plot columns 1 and 3 of "data" with a line of linetype 3.

This has become an issue for me lately since I've started using the
multiplot environment in gnuplot and have to adjust sizes in scripts
for various terminal types.  BTW, I'm currently using Octave 1.1.1 (Linux ELF
binary under kernel 2.0.0) and gnuplot 3.6 patch 315.  Any suggestions?

Ronald Kumon
Department of Physics          
University of Texas at Austin
Austin, TX  78712-1081          
http://www.ph.utexas.edu/~kumon/




Reply | Threaded
Open this post in threaded view
|

Variables in gnuplot commands

John W. Eaton-6
On 17-Nov-1996, Ronald Kumon <[hidden email]> wrote:

: Does anyone know why you cannot use variables in gnuplot "set" commands
: from within Octave?

Yes.

: For example, in gnuplot you can execute the commands:
:
: gnuplot> xsize=0.5
: gnuplot> ysize=0.5
: gnuplot> set size xsize,ysize
: gnuplot> show size
:
:          size is scaled by 0.5,0.5
:          no attempt to control aspect ratio
:
: However, the corresponding commands in octave give:
:
: octave> xsize=0.5
: octave> ysize=0.5
: octave> set size xsize,ysize
: octave>          line 0: undefined variable: xsize

This happens because Octave only parses the set command by noting that
it is a set command and then passing all the remaining text (up until
the next newline or semicolon) directly to gnuplot.  It never notices
that there might be variables that should be expanded.

: Interestingly enough, variable substitution does occur automatically
: in the gplot command since
:
: octave> ltnum=3
: octave> gplot "data" using 1:3 with lines ltnum
:
: will successfully plot columns 1 and 3 of "data" with a line of linetype 3.

This works because Octave does parse the complete gplot command, and
performs the appropriate variable substitutions.  Doing the same for
the set command would be a lot of work because gnuplot's set command
has a lot of different options.  I'm not sure that it is worth the
effort.

Thanks,

jwe

Reply | Threaded
Open this post in threaded view
|

Re: Variables in gnuplot commands

Dutt, Vinayak, Ph.D.
In reply to this post by Ronald Kumon
John Eaton wrote (in reply to Ron Kumon's query):
#
#: Does anyone know why you cannot use variables in gnuplot "set" commands
#: from within Octave?
#
#Yes.
#:
#: octave> xsize=0.5
#: octave> ysize=0.5
#: octave> set size xsize,ysize
#: octave>          line 0: undefined variable: xsize
#
#This happens because Octave only parses the set command by noting that
#it is a set command and then passing all the remaining text (up until
#the next newline or semicolon) directly to gnuplot.  It never notices
#that there might be variables that should be expanded.
#

Well, there are benefits to Octave not parsing set command. When gnuplot
updates add more set options, I don't have to wait for Octave updating its
parser for the new options. Thus gnuplot 3.6 (beta) can now be used without
having to wait for next release of Octave. The fact that gplot and gsplot
do parse the command kind of causes problems with using newer line styles
of gnuplot 3.6 (for example boxerrorbars can not be used with gplot and
gsplot), but again as set command is not parsed, I can overcome this
restriction with using set command instead ("set data style boxerrorbars").

Anyway, I just wanted to point out that set no being parsed is also beneficial
in some way :-)

Vinayak Dutt

Ultrasound Research
Mayo Clinic
Rochester MN 55905
E-Mail: [hidden email]