Hi, The command qualifier PLOT/KEY=title will use the titles from the variables in the legend of a line plot. Try this example yes? let/title="Line one" _one_ = 3*X+2 (I also used PLOT/COLOR there. This is a fairly recent addition; PLOT/COLOR with no argument will skip black as a color and start with the colored lines.) For your script, the problem is that you can't nest grave-accent
expressions, but you can have a symbol evaluation inside a
grave-accent _expression_. Something along these lines should work: !MAIN: PLOTTING (2)
plot/thick=
1/vlim=25:31:0.2 /color=19 a19
repeat/name=mn/range=1:18 (\ plot/over/thick=1/vlim=25:31:0.2/symbol=`mn`/line=`mn` a`mn`;\ define symbol mn= `mn`;\
go legend `mn` "`a($mn),return=title`" ur;\
ppl plot;\ ) There is yet another option, a new script linekey.jnl, which was just added and is not yet in the PyFerret/Ferret releases. It was mentioned here, https://www.pmel.noaa.gov/maillists/tmap/ferret_users/fu_2019/msg00183.html. I have attached linekey.jnl and test_linekey.jnl which is a demo script that calls it. This lets you put the legend inside the plot box or outside its edges, and gives control over symbols used in the line samples. Ansley On 8/5/2019 6:51 PM, Saat Mubarrok
wrote:
--
Ansley Manke NOAA/PMEL Science Data Integration Group 7600 Sand Point Way NE 206-526-6246 |
\cancel mode verify ! ! linekey.jnl ! Draw a labeled line sample on a plot, a single line in a legend. ! User-specified PLOT command with qualifiers for line style, color, ! symbol, thickness. ! ! 5/22/2019 ! ! Arguments ! 1 line number ! 2 title ! 3 plot command with thickness, color, symbol, size ! 4 location on the page ul ur ll lr ulc urc llc lrc, where: ! ul, ur, ll, lr are upper left, upper right etc, within the plot box ! ulc, urc, llc, lrc are upper left corner, etc outside the plot box. ! ! For legends in the plot corners, you may need to increase the margins for them to fit. ! See the margins script: yes? GO/HELP margins.jnl ! To make the legend in the upper right of a page, use "CANCEL MODE LOGO" ! to remove the ferret-version and date lines. ! ! Example: ! cancel mode logo ! go margins 1.4 1.4 1.2 1.2 ! ! plot/i=1:60/thick/sym=20 cos(i/10) ! plot/over/nolab/i=1:60/thick/size=0.16/line/sym=30/color=red sin(i/10) ! go linekey 1 "cosine" plot/thick/sym=20/color=black ur ! go linekey 2 "sine" plot/thick/size=0.16/line/sym=30/color=red ur ! ! NOTE: For time plots, when running PyFerret, if you have issued SET TEXT for system fonts ! this script issues a CANCEL TEXT because the text is mis-located using SET TEXT. ! ! For the legends drawn within the plot box, the first line is drawn nearest ! the upper or lower axis line of the plot, with each new line drawn below that ! for upper-located legends or above for lower-located ones. ! For legends drawn outside the plot box, the first line is drawn nearest the plot ! box. For upper-located legends the first line is drawn just above the upper axis ! with more lines added above that. For lower-located legends the first line is drawn ! just below the bottom axis with more lines added below that. DEFINE SYMBOL lk_lnum = ($1) DEFINE SYMBOL lk_title = ($2%" "%) DEFINE SYMBOL plot_command = `upcase("($3)")` DEFINE SYMBOL lk_where = ($4) DEFINE SYMBOL lk_lsize = ($5"0") query/ignore $4%1|ul>1|ur>1|ll>1|lr>1|ulc>1|urc>1|llc>1|lrc>1|\ <location must be ul, ur, ll, lr, ulc, urc, llc or lrc% ! currently SET TEXT setting mis-positions the text on some plots (time-axis plots?) IF `($program_name"0|PyFerret>1|*>0") and ($AX_HORIZ%0|T>1|*>0%) or ($AX_VERT%0|T>1|*>0%)` THEN CANCEL TEXT ENDIF IF `substring("($plot_command)", 1,1) NE "P"` THEN SAY Argument 3 must be a PLOT command, e.g. PLOT/COLOR=RED EXIT/SCRIPT ENDIF DEFINE SYMBOL plot_command = ($plot_command)/NOLAB/OVER/VS IF `($lk_lsize) EQ 0` THEN DEFINE SYMBOL lk_lsize = 0.11 ! IF it's not explicitly plot/sym= THEN add /line. By default plot/vs makes symbol plots IF `STRINDEX("($plot_command)", "SY") EQ 0` THEN DEFINE SYMBOL plot_command = ($plot_command)/line LET lk_xrange = ($XAXIS_MAX)-(($XAXIS_MIN)) LET lk_yrange = ($YAXIS_MAX)-(($YAXIS_MIN)) LET lk_aspect = ($PPL$HEIGHT)/($PPL$WIDTH) LET lk_xdel = 0.04* lk_aspect LET lk_ydel = 0.03/ lk_aspect ! expand things a bit IF we're in a viewport LET lk_xdel = `lk_xdel/(($vp_xhi%1%)-($vp_xlo%0%))` LET lk_ydel = `lk_ydel/(($vp_yhi%1%)-($vp_ylo%0%))` IF `($lk_where%1|ul>1|*>0%) EQ 1` THEN ! left top LET lk_x1pt = (0.5*lk_xdel)* lk_xrange + (($XAXIS_MIN)) LET lk_x2pt = lk_xdel*lk_xrange + lk_x1pt LET lk_yfac = (1-0.5*lk_ydel) - (($1)-1)* lk_ydel LET lk_y1pt = lk_yfac * lk_yrange + ($YAXIS_MIN) ($plot_command) {`lk_x1pt`,`lk_x2pt`}, {`lk_y1pt`, `lk_y1pt`} LET lk_xlabloc = lk_x2pt + 0.02*lk_xrange IF ($AX_HORIZ%0|T>1|*>0%) THEN LET lk_xlabloc = ($PPL$XMAX1)+ 0.02*LK_XRANGE ANNOTATE/XPOS=`lk_xlabloc`/YPOS=`lk_y1pt`/HALIGN=-1/VALIGN=0/SIZE=($lk_lsize) "($lk_title)" ELIF `($lk_where%1|ur>1|*>0%) EQ 1` THEN ! right top LET lk_x1pt = (1-1.5*lk_xdel)* lk_xrange + (($XAXIS_MIN)) LET lk_x2pt = lk_xdel*lk_xrange + lk_x1pt LET lk_yfac = (1-0.5*lk_ydel) - (($1)-1)* lk_ydel LET lk_y1pt = lk_yfac * lk_yrange + ($YAXIS_MIN) LET lk_xlabloc = lk_x1pt - 0.02*lk_xrange ($plot_command) {`lk_x1pt`,`lk_x2pt`}, {`lk_y1pt`, `lk_y1pt`} LET lk_xlabloc = lk_x1pt - 0.02*lk_xrange IF ($AX_HORIZ%0|T>1|*>0%) THEN LET lk_xlabloc = ($PPL$XMAX1) - 0.06*LK_XRANGE ANNOTATE/XPOS=`lk_xlabloc`/YPOS=`lk_y1pt`/HALIGN=1/VALIGN=0/SIZE=($lk_lsize) "($lk_title)" ELIF `($lk_where%1|ll>1|*>0%) EQ 1` THEN ! left bottom LET lk_x1pt = (0.5*lk_xdel)* lk_xrange + (($XAXIS_MIN)) LET lk_x2pt = lk_xdel*lk_xrange + lk_x1pt LET lk_yfac = 0.5*lk_ydel + (($1)-1)* lk_ydel LET lk_y1pt = lk_yfac * lk_yrange + ($YAXIS_MIN) ($plot_command) {`lk_x1pt`,`lk_x2pt`}, {`lk_y1pt`, `lk_y1pt`} LET lk_xlabloc = lk_x2pt + 0.02*lk_xrange IF ($AX_HORIZ%0|T>1|*>0%) THEN LET lk_xlabloc = ($PPL$XMAX1)+ 0.02*LK_XRANGE ANNOTATE/XPOS=`lk_xlabloc`/YPOS=`lk_y1pt`/HALIGN=-1/VALIGN=0/SIZE=($lk_lsize) "($lk_title)" ELIF `($lk_where%1|lr>1|*>0%) EQ 1` THEN ! right bottom LET lk_x1pt = (1-1.5*lk_xdel)* lk_xrange + (($XAXIS_MIN)) LET lk_x2pt = lk_xdel*lk_xrange + lk_x1pt LET lk_yfac = 0.5*lk_ydel + (($1)-1)* lk_ydel LET lk_y1pt = lk_yfac * lk_yrange + ($YAXIS_MIN) ($plot_command) {`lk_x1pt`,`lk_x2pt`}, {`lk_y1pt`, `lk_y1pt`} LET lk_xlabloc = lk_x1pt - 0.02*lk_xrange IF ($AX_HORIZ%0|T>1|*>0%) THEN LET lk_xlabloc = ($PPL$XMAX1) - 0.06*LK_XRANGE ANNOTATE/XPOS=`lk_xlabloc`/YPOS=`lk_y1pt`/HALIGN=1/VALIGN=0/SIZE=($lk_lsize) "($lk_title)" ENDIF ! legends in the plot corners. ! set up to draw outside the plot box IF `($lk_where%|ulc>1|urc>1|llc>1|lrc>1|*>0%) EQ 1` THEN PPL WINDOW,OFF IF `($lk_where%1|ulc>1|*>0%) EQ 1` THEN ! left top LET lk_x1pt = (0.5*lk_xdel)* lk_xrange + (($XAXIS_MIN) - 4*lk_xdel*lk_xrange) LET lk_x2pt = lk_xdel*lk_xrange + lk_x1pt LET lk_yfac = (1-0.5*lk_ydel) + (($1)-1)* lk_ydel LET lk_y1pt = lk_yfac * lk_yrange + (($YAXIS_MIN) + 2*lk_ydel*lk_yrange) ($plot_command) {`lk_x1pt`,`lk_x2pt`}, {`lk_y1pt`, `lk_y1pt`} LET lk_xlabloc = lk_x2pt + 0.02*lk_xrange IF ($AX_HORIZ%0|T>1|*>0%) THEN LET lk_xlabloc = ($PPL$XMAX1)+ 0.02*LK_XRANGE ANNOTATE/XPOS=`lk_xlabloc`/YPOS=`lk_y1pt`/HALIGN=-1/VALIGN=0/SIZE=($lk_lsize) "($lk_title)" ELIF `($lk_where%1|urc>1|*>0%) EQ 1` THEN ! right top LET lk_x1pt = (1-1.5*lk_xdel)* lk_xrange + (($XAXIS_MIN) + 4*lk_xdel*lk_xrange) LET lk_x2pt = lk_xdel*lk_xrange + lk_x1pt LET lk_yfac = (1-0.5*lk_ydel) + (($1)-1)* lk_ydel LET lk_y1pt = lk_yfac * lk_yrange + (($YAXIS_MIN) + 2*lk_ydel*lk_yrange) ($plot_command) {`lk_x1pt`,`lk_x2pt`}, {`lk_y1pt`, `lk_y1pt`} LET lk_xlabloc = lk_x1pt - 0.02*lk_xrange IF ($AX_HORIZ%0|T>1|*>0%) THEN LET lk_xlabloc = ($PPL$XMAX1) - 0.06*LK_XRANGE ANNOTATE/XPOS=`lk_xlabloc`/YPOS=`lk_y1pt`/HALIGN=1/VALIGN=0/SIZE=($lk_lsize) "($lk_title)" ELIF `($lk_where%1|llc>1|*>0%) EQ 1` THEN ! left bottom LET lk_x1pt = (0.5*lk_xdel)* lk_xrange + (($XAXIS_MIN) - 4*lk_xdel*lk_xrange) LET lk_x2pt = lk_xdel*lk_xrange + lk_x1pt LET lk_yfac = 0.5*lk_ydel - (($1)-1)* lk_ydel LET lk_y1pt = lk_yfac * lk_yrange + (($YAXIS_MIN) - 2.5*lk_ydel*lk_yrange) ($plot_command) {`lk_x1pt`,`lk_x2pt`}, {`lk_y1pt`, `lk_y1pt`} LET lk_xlabloc = lk_x2pt + 0.02*lk_xrange IF ($AX_HORIZ%0|T>1|*>0%) THEN LET lk_xlabloc = ($PPL$XMAX1)+ 0.02*LK_XRANGE ANNOTATE/XPOS=`lk_xlabloc`/YPOS=`lk_y1pt`/HALIGN=-1/VALIGN=0/SIZE=($lk_lsize) "($lk_title)" ELIF `($lk_where%1|lrc>1|*>0%) EQ 1` THEN ! right bottom LET lk_x1pt = (1-1.5*lk_xdel)* lk_xrange + (($XAXIS_MIN) + 4*lk_xdel*lk_xrange) LET lk_x2pt = lk_xdel*lk_xrange + lk_x1pt LET lk_yfac = 0.5*lk_ydel - (($1)-1)* lk_ydel LET lk_y1pt = lk_yfac * lk_yrange + (($YAXIS_MIN) - 2.5*lk_ydel*lk_yrange) ($plot_command) {`lk_x1pt`,`lk_x2pt`}, {`lk_y1pt`, `lk_y1pt`} LET lk_xlabloc = lk_x1pt - 0.02*lk_xrange IF ($AX_HORIZ%0|T>1|*>0%) THEN LET lk_xlabloc = ($PPL$XMAX1) - 0.06*LK_XRANGE ANNOTATE/XPOS=`lk_xlabloc`/YPOS=`lk_y1pt`/HALIGN=1/VALIGN=0/SIZE=($lk_lsize) "($lk_title)" ENDIF ppl window,on cancel variale lk_*
! test_linekey.jnl ! Examples using the "linekey.jnl" script for legend lines. cancel mode logo go margins 1.4 1.4 1.2 1.2 ! Draw an example pair of lines, and show all of the different legend ! locations plot/i=1:60/thick/sym=20 cos(i/10) plot/over/nolab/i=1:60/thick/size=0.16/line/sym=30/color=red sin(i/10) go linekey.jnl 1 "title one" plot/thick/sym=20/color=black ur .12 go linekey.jnl 2 "title two" plot/thick/size=0.16/line/sym=30/color=red ur .12 go linekey.jnl 1 "title one" plot/thick/sym=20/color=black ul .14 go linekey.jnl 2 "title two" plot/thick/size=0.16/line/sym=30/color=red ul .14 go linekey.jnl 1 "title two" plot/thick/size=0.16/line/sym=30/color=red ll .10 go linekey.jnl 2 "title one" plot/thick/sym=20/color=black ll .10 go linekey.jnl 1 "title two" plot/thick/size=0.16/line/sym=30/color=red lr .16 go linekey.jnl 2 "title one" plot/thick/sym=20/color=black lr .16 ! Now the legends outside the plot box go linekey.jnl 1 "title one" plot/thick/sym=20/color=black urc .12 go linekey.jnl 2 "title two" plot/thick/size=0.16/line/sym=30/color=red urc .12 go linekey.jnl 1 "title one" plot/thick/sym=20/color=black ulc .08 go linekey.jnl 2 "title two" plot/thick/size=0.16/line/sym=30/color=red ulc .08 go linekey.jnl 1 "title one" plot/thick/sym=20/color=black llc .18 go linekey.jnl 2 "title two" plot/thick/size=0.16/line/sym=30/color=red llc .18 go linekey.jnl 1 "title one" plot/thick/sym=20/color=black lrc .11 go linekey.jnl 2 "title two" plot/thick/size=0.16/line/sym=30/color=red lrc .11 message now show the example as in test_legend.jnl that used the older legend.jnl script cancel mode logo let one=3*x+2 let two=x*x-5 let three=0*x+3 set region /x=-10:10 set viewport ul go margins 1.4 1.4 1.2 1.2 plot/title="test plot" one,two,three go linekey 1 "Variable one" plot/color=black ul go linekey 2 "Variable two" plot/color=red ul go linekey 3 "Variable three" plot/color=green ul set viewport ur go margins 1.4 1.4 1.2 1.2 plot/title="test plot" one,two,three go linekey 1 "Variable one" plot/color=black ur go linekey 2 "Variable two" plot/color=red ur go linekey 3 "Variable three" plot/color=green ur set viewport ll go margins 1.4 1.4 1.2 1.2 plot/title="test plot" one,two,three go linekey 1 "Variable one" plot/color=black ll go linekey 2 "Variable two" plot/color=red ll go linekey 3 "Variable three" plot/color=green ll set viewport lr go margins 1.4 1.4 1.2 1.2 plot/title="test plot" one,two,three go linekey 1 "Variable one" plot/color=black lr go linekey 2 "Variable two" plot/color=red lr go linekey 3 "Variable three" plot/color=green lr message now draw legends outside the plot boxes. cancel view set viewport ul go margins 1.4 1.4 1.2 1.2 plot/title="test plot" one,two,three go linekey 1 "Variable one" plot/color=black ulc go linekey 2 "Variable two" plot/color=red ulc go linekey 3 "Variable three" plot/color=green ulc set viewport ur go margins 1.4 1.4 1.2 1.2 plot/title="test plot" one,two,three go linekey 1 "Variable one" plot/color=black urc go linekey 2 "Variable two" plot/color=red urc go linekey 3 "Variable three" plot/color=green urc set viewport ll go margins 1.4 1.4 1.2 1.2 plot/title="test plot" one,two,three go linekey 1 "Variable one" plot/color=black llc go linekey 2 "Variable two" plot/color=red llc go linekey 3 "Variable three" plot/color=green llc set viewport lr go margins 1.4 1.4 1.2 1.2 plot/title="test plot" one,two,three go linekey 1 "Variable one" plot/color=black lrc go linekey 2 "Variable two" plot/color=red lrc go linekey 3 "Variable three" plot/color=green lrc ! Now tests on time plots cancel view use monthly_navy_winds plot/title=" "/t=1-jan-1982:31-dec-1985/x=180/y=20 uwnd plot/over/nolab/t=1-jan-1982:31-dec-1985/x=180/y=20/thick/size=0.16/line/sym=30/color=red vwnd go linekey.jnl 1 "`uwnd,return=title`" plot/thick/sym=20/color=black ur .12 go linekey.jnl 2 "`vwnd,return=title`" plot/thick/size=0.16/line/sym=30/color=red ur .12 go linekey.jnl 1 "`uwnd,return=title`" plot/thick/sym=20/color=black ul .14 go linekey.jnl 2 "`vwnd,return=title`" plot/thick/size=0.16/line/sym=30/color=red ul .14 go linekey.jnl 1 "title two" plot/thick/size=0.16/line/sym=30/color=red ll .10 go linekey.jnl 2 "title one" plot/thick/sym=20/color=black ll .10 go linekey.jnl 1 "title two" plot/thick/size=0.16/line/sym=30/color=red lr .16 go linekey.jnl 2 "title one" plot/thick/sym=20/color=black lr .16 ! Now the legends outside the plot box go linekey.jnl 1 "`uwnd,return=title`" plot/thick/sym=20/color=black urc .12 go linekey.jnl 2 "`vwnd,return=title`" plot/thick/size=0.16/line/sym=30/color=red urc .12 go linekey.jnl 1 "`uwnd,return=title`" plot/thick/sym=20/color=black ulc .08 go linekey.jnl 2 "`vwnd,return=title`" plot/thick/size=0.16/line/sym=30/color=red ulc .08 go linekey.jnl 1 "`uwnd,return=title`" plot/thick/sym=20/color=black llc .18 go linekey.jnl 2 "`vwnd,return=title`" plot/thick/size=0.16/line/sym=30/color=red llc .18 go linekey.jnl 1 "`uwnd,return=title`" plot/thick/sym=20/color=black lrc .11 go linekey.jnl 2 "`vwnd,return=title`" plot/thick/size=0.16/line/sym=30/color=red lrc .11 message now show the example as in test_legend.jnl that used the older legend.jnl script cancel mode logo set region /x=-10:10 set viewport ul go margins 1.4 1.4 1.2 1.2 plot/title="`uwnd,return=title`"/t=1-jan-1982:31-dec-1985/x=120 uwnd[y=-20], uwnd[y=-0], uwnd[y=20] go linekey 1 "Y=-20" plot/color=black ul go linekey 2 "Y=0" plot/color=red ul go linekey 3 "Y=20" plot/color=green ul set viewport ur go margins 1.4 1.4 1.2 1.2 plot/title="`uwnd,return=title`"/t=1-jan-1982:31-dec-1985/x=120 uwnd[y=-20], uwnd[y=-0], uwnd[y=20] go linekey 1 "Y=-20" plot/color=black ur go linekey 2 "Y=0" plot/color=red ur go linekey 3 "Y=20" plot/color=green ur set viewport ll go margins 1.4 1.4 1.2 1.2 plot/title="`uwnd,return=title`"/t=1-jan-1982:31-dec-1985/x=120 uwnd[y=-20], uwnd[y=-0], uwnd[y=20] go linekey 1 "Y=-20" plot/color=black ll go linekey 2 "Y=0" plot/color=red ll go linekey 3 "Y=20" plot/color=green ll set viewport lr go margins 1.4 1.4 1.2 1.2 plot/title="`uwnd,return=title`"/t=1-jan-1982:31-dec-1985/x=120 uwnd[y=-20], uwnd[y=-0], uwnd[y=20] go linekey 1 "Y=-20" plot/color=black lr go linekey 2 "Y=0" plot/color=red lr go linekey 3 "Y=20" plot/color=green lr message now draw legends outside the plot boxes. cancel view set viewport ul go margins 1.4 1.4 1.2 1.2 plot/title="`uwnd,return=title`"/t=1-jan-1982:31-dec-1985/x=120 uwnd[y=-20], uwnd[y=-0], uwnd[y=20] go linekey 1 "Y=-20" plot/color=black ulc go linekey 2 "Y=0" plot/color=red ulc go linekey 3 "Y=20" plot/color=green ulc set viewport ur go margins 1.4 1.4 1.2 1.2 plot/title="`uwnd,return=title`"/t=1-jan-1982:31-dec-1985/x=120 uwnd[y=-20], uwnd[y=-0], uwnd[y=20] go linekey 1 "Y=-20" plot/color=black urc go linekey 2 "Y=0" plot/color=red urc go linekey 3 "Y=20" plot/color=green urc set viewport ll go margins 1.4 1.4 1.2 1.2 plot/title="`uwnd,return=title`"/t=1-jan-1982:31-dec-1985/x=120 uwnd[y=-20], uwnd[y=-0], uwnd[y=20] go linekey 1 "Y=-20" plot/color=black llc go linekey 2 "Y=0" plot/color=red llc go linekey 3 "Y=20" plot/color=green llc set viewport lr go margins 1.4 1.4 1.2 1.2 plot/title="`uwnd,return=title`"/t=1-jan-1982:31-dec-1985/x=120 uwnd[y=-20], uwnd[y=-0], uwnd[y=20] go linekey 1 "Y=-20" plot/color=black lrc go linekey 2 "Y=0" plot/color=red lrc go linekey 3 "Y=20" plot/color=green lrc