[Thread Prev][Thread Next][Index]

legend script



I've finished a script to create a legend for a plot with multiple
lines or contours. It will draw a legend for each line in a specified
corner of the plot, with a sample line.

usage:

plot /set_up /nolabel var1, var2, var3
     go legend 1 var1
     go legend 2 var2
     go legend 3 var3
ppl plot

or

plot /set_up /nolabel var1, var2, var3
     go legend 1 var1 ur
     go legend 2 var2 ur
     go legend 3 var3 ur
ppl plot

where "ur" is the corner where you want the legend, ul is default.
The script has a few remaining drawbacks:

- will only work with plot/set_up, not with plot/overlay
- you can't skip lines
- when using bottom corners, legends are built up from bottom to top.

If anyone knows how to improve that, I'd be happy to hear from
them. Comments welcome.

      Hein Zelle

>-----------------------------------------------------------------<
    Hein Zelle
    Dept. of Oceographic Research
    KNMI, The Netherlands
    work:        zelle@knmi.nl     http://www.knmi.nl/~zelle
    private:     hein@icce.rug.nl  http://www.icce.rug.nl/~hein
    Phone:       +31 (0)30 2206704
>-----------------------------------------------------------------<
--------------------------------------------------------------
Zie ook/see also: http://www.knmi.nl/maildisclaimer.html 
\cancel mode verify

! script to add a legend line to a plot
! use this between plot/set_up and ppl plot.
! it may also work before a plot/overlay, but I'm not sure.
! if it doesn't, change it to use immediate mode: remove the "on"
! argument to ppl aline. For skipping lines we'll need to write a more
! advanced script that keeps track of how many times we've been called
! sofar.
!
! go legend line# title [orientation]
! 
! where orientation is one of ul, ur, ll or lr
! default orientation is ul

query/ignore $1%<usage: go legend line# title [orientation: ul* ur ll lr]%
query/ignore $2%<usage: go legend line# title [orientation: ul* ur ll lr]%
query/ignore $3%1|ul>1|ur>2|ll>3|lr>4|<orientation must be ul, ur, ll or lr%

if `$3%1|ul>1|ur>2|ll>3|lr>4|% eq 1` then     ! left top

  ppl aline/nouser $1,0.1,`($PPL$YLEN)-0.2*$1`,0.5,`($PPL$YLEN)-0.2*$1`,on
  ppl labs/nouser $1,0.6,`($PPL$YLEN)-0.05-0.2*$1`,-1,"$2"

elif `$3%1|ul>1|ur>2|ll>3|lr>4|% eq 2` then   ! right top

  ppl aline/nouser $1,`($PPL$XLEN)-0.1`,`($PPL$YLEN)-0.2*$1`,`($PPL$XLEN)-0.5`,`($PPL$YLEN)-0.2*$1`,on
  ppl labs/nouser $1,`($PPL$XLEN)-0.6`,`($PPL$YLEN)-0.05-0.2*$1`,1,"$2"

elif `$3%1|ul>1|ur>2|ll>3|lr>4|% eq 3` then   ! left bottom

  ppl aline/nouser $1,0.1,`0.2*$1`,0.5,`0.2*$1`,on
  ppl labs/nouser $1,0.6,`-0.05+0.2*$1`,-1,"$2"

else                                          ! right bottom

  ppl aline/nouser $1,`($PPL$XLEN)-0.1`,`0.2*$1`,`($PPL$XLEN)-0.5`,`0.2*$1`,on
  ppl labs/nouser $1,`($PPL$XLEN)-0.6`,`-0.05+0.2*$1`,1,"$2"

endif

say label `$1`: "$2"

set mode /last verify
let one=3*x+2
let two=x*x-5
let three=0*x+3

set region /x=-10:10

set viewport ul
plot /set_up /nolabel one,two,three
ppl title "test plot"
ppl xlab "X axis"
ppl ylab "Y axis"
go legend 1 "Variable one"
go legend 2 "Variable two" 
go legend 3 "Variable three"
ppl plot

set viewport ur
plot /set_up /nolabel one,two,three
ppl title "test plot"
ppl xlab "X axis"
ppl ylab "Y axis"
go legend 1 "Variable one" ur
go legend 2 "Variable two" ur
go legend 3 "Variable three" ur
ppl plot

set viewport ll
plot /set_up /nolabel one,two,three
ppl title "test plot"
ppl xlab "X axis"
ppl ylab "Y axis"
go legend 1 "Variable one" ll
go legend 2 "Variable two" ll
go legend 3 "Variable three" ll
ppl plot

set viewport lr
plot /set_up /nolabel one,two,three
ppl title "test plot"
ppl xlab "X axis"
ppl ylab "Y axis"
go legend 1 "Variable one" lr
go legend 2 "Variable two" lr
go legend 3 "Variable three" lr
ppl plot

[Thread Prev][Thread Next][Index]

Dept of Commerce / NOAA / OAR / PMEL / TMAP

Contact Us | Privacy Policy | Disclaimer | Accessibility Statement