[ncl-talk] legend

David Bailey dbailey at ucar.edu
Sat Mar 17 13:33:28 MDT 2018


I will just jump in here and say that I used it and it works great for me.
See the following plot:

http://webext.cgd.ucar.edu/B20TH/b.e20.BHIST.f09_g17.20thC.269_01/ice/b.e20.BHIST.f09_g17.20thC.269_01-obs/yrs1850-2005/obs/fm_icesat_barchart.png

Here is the code I used:

;
; Add a legend.
;
  gres = True
  gres at YPosPercent = 95.    ; expressed as %, 0->100, sets position of top
border of legend
                            ;  when gres at Position is set to its default
setting of "Top" (Default = 95.)
  gres at XPosPercent = 30.    ; expressed as %, 0->100, sets position of left
border of legend(Default = 5.)

  lineres = True
  lineres at lgLineColors = (/"gray55","black"/) ; line colors
  lineres at lgLineThicknesses = (/30,3/)                    ; line thicknesses
  lineres at LineLengthPercent = 9.                         ; expressed as %,
0->100, length of line

  textres = True
  textres at lgLabels = labels  ; legend labels (required)
  textres at lgLabelFontHeights = (/0.010,0.010/)

  res at tiMainString = "Spring (FM)"
  plot1(0) = gsn_csm_xy (wks1,level(0:13),spring(1,:),res)
  res at trYMaxF = 0.5
  res at tiMainString = "Fall (ON)"
  plot1(1) = gsn_csm_xy (wks2,level(0:13),fall(1,:),res)

  plot1(0) = simple_legend(wks1,plot1(0),gres,lineres,textres)
  plot1(1) = simple_legend(wks2,plot1(1),gres,lineres,textres)

  draw(plot(0))
  draw(plot(1))
  draw(plot1(0))
  draw(plot1(1))

  overlay(plot(0),plot1(0))
  overlay(plot(1),plot1(1))

  frame(wks1)
  frame(wks2)

Dave

On Sat, Mar 17, 2018 at 1:11 PM, Mary Haley <haley at ucar.edu> wrote:

> Sandro,
>
> On the same legend page that Rick pointed you to, you could also check out
> the "simple_legend" function that Adam Phillips created. Examples 16, 17,
> and 19 show how to use this function.
>
> If you need to draw the legend outside the plot, then simple_legend_ndc
> can be used. This function has not yet been released, so I've attached it
> here. You would need to load it with:
>
> load "./simple_legend_ndc.ncl"
>
> Examples 20 and 21 show how to use that function.
>
> --Mary
>
>
> On Sat, Mar 17, 2018 at 7:46 AM, Rick Brownrigg <brownrig at ucar.edu> wrote:
>
>> Hi,
>>
>> I now understand what you are saying. I'm not expert at this, but I
>> wonder if pmLegendWidthF is the resource you need (
>> http://ncl.ucar.edu/Document/Graphics/Resources/pm.shtml). There are
>> several examples that explicitly set this at:
>>
>>     http://ncl.ucar.edu/Applications/legend.shtml
>>
>> If that does not help, please reply back to ncl-talk, as perhaps others
>> with more experience can offer advise.
>>
>> Rick
>>
>> On Fri, Mar 16, 2018 at 10:06 PM, Vattioni Sandro <
>> sandro.vattioni at outlook.com> wrote:
>>
>>> Hi Rick
>>>
>>> Thanks for your fast answer.
>>> Attached I’m sending you a screen-shot.
>>> I just want to decrease the length of the dash paterns in the legend. It
>>> looks kind of silly when they are so long. I tried to draw the desired
>>> outcome 😃
>>>
>>> Thank you very much for your help.
>>>
>>> Sandro
>>>
>>> *Von:* Rick Brownrigg <brownrig at ucar.edu>
>>> *Gesendet:* ‎Freitag‎, ‎16‎. ‎März‎ ‎2018 ‎23‎:‎34
>>> *An:* Vattioni Sandro <sandro.vattioni at outlook.com>
>>> *Cc:* ncl-talk at ucar.edu
>>>
>>> Hi Sandro,
>>>
>>> Can you post a picture of what you talking about? I am having trouble
>>> visualizing what the issue is... :-/
>>>
>>> Rick
>>>
>>> On Fri, Mar 16, 2018 at 9:15 PM, Vattioni Sandro <
>>> sandro.vattioni at outlook.com> wrote:
>>>
>>>> Dear Madam or Sir
>>>>
>>>> I wnat to draw a legend for my xy-plot in ncl, but the dash patern of
>>>> the line is very long compared to the text. I tried to make the dash
>>>> pattern shorter with lgLineDashSegLenF but it did not work. How can I
>>>> controll the length of the dash pattern using the legendClass?
>>>>
>>>> Kind regards,
>>>> Sandro
>>>>
>>>> legend = create "Legend" legendClass wks
>>>>    "lgTitleString"            : "Left Hand Side Column:
>>>> 10~F34~0~F~N-10~F34~0~F~S emission"
>>>>    "vpXF"                     : 0.2                  ; orientation on
>>>> page
>>>>    "vpYF"                     : 0.15  ;0.48
>>>>    "vpWidthF"                 : 0.1 ;0.3                     ; width
>>>>    "vpHeightF"                : 0.12                    ; height
>>>>    "lgAutoManage"             : True
>>>>    "lgPerimOn"                : False                   ; no perimeter
>>>>    "lgItemCount"              : 5                      ; how many
>>>>    "lgItemType"               : "Lines"
>>>>    "lgLabelStrings"           : (/"Reference run","Continuous aerosol
>>>> emission","Continuous
>>>>    "lgLabelsOn"               : True                    ; no default
>>>> lables
>>>>    "lgLabelOffsetF"           : 0.0
>>>>    "lgLineLabelFontHeightF"   : 2.0
>>>>    "lgLineDashSegLenF"        : 0.01
>>>>    "lgDashIndexes"            : (/0,0,0,0,0/)   ;4
>>>>    "lgLineColors"             : (/"black","blue","red","darkvi
>>>> olet","orange"/)
>>>>
>>>>  end create
>>>>
>>>>  draw(legend)
>>>>
>>>>
>>>> _______________________________________________
>>>> ncl-talk mailing list
>>>> ncl-talk at ucar.edu
>>>> List instructions, subscriber options, unsubscribe:
>>>> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>>>>
>>>>
>>>
>>
>> _______________________________________________
>> ncl-talk mailing list
>> ncl-talk at ucar.edu
>> List instructions, subscriber options, unsubscribe:
>> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>>
>>
>
> _______________________________________________
> ncl-talk mailing list
> ncl-talk at ucar.edu
> List instructions, subscriber options, unsubscribe:
> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>
>


-- 

David A Bailey
 email: dbailey_at_ucar.edu
National Center for Atmospheric Research   phone: 303-497-1737
PO Box 3000
fax  : 303-497-1700
Boulder, CO 80307-3000
                   http://www.cgd.ucar.edu/staff/dbailey
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20180317/d5ae6bfa/attachment.html>


More information about the ncl-talk mailing list