problem by adding legend for plotting

From: Ping Yang <pyang_at_nyahnyahspammersnyahnyah>
Date: Mon Oct 15 2012 - 16:43:41 MDT

Hi NCL,

I followed the example xy_20(
http://www.ncl.ucar.edu/Applications/Scripts/xy_20.ncl) for adding a legend
to plot, but failed, the code I used:
;************************************************
; create plots: Three res for three variables.
;************************************************
  pwks = gsn_open_wks("ps" ,"ISIMIP_MERRA_NCEP_xy") ;
ps,pdf,x11,ncgm,eps
; xwks = gsn_open_wks("x11","ISIMIP_MERRA_NCEP_xy")

; t = ut_calendar(t,1);change to the calendar year
 res = True ; plot mods desired
; res@gsnMaximize = True
; res@trXmaxF = max(m)
 res@tiMainString = "Precipitation ISIMIP/NCEP/MERRA" ; add
title
 res@xyLineColors =(/"blue","red","green"/)
 res@xyLineThicknesses = (/3.0,3.0,4.0/)
 res@xyDashPattern = 0 ; Make curves all solid
 plot = gsn_csm_xy (pwks,m,data,res) ; create plot
; plot = gsn_csm_xy (xwks,m,data,res)

;*****************************************************

;set up resources for a customized legend.
  lgres = True
  lgres@lgLineColors = (/"blue","red","green"/)
  lgres@lgItemType = "Lines" ; show lines only (default)
  lgres@lgLabelFontHeightF = .08 ; legend label font thickness
  lgres@vpWidthF = 0.13 ; width of legend (NDC)
  lgres@vpHeightF = 0.10 ; height of legend (NDC)
  lgres@lgPerimThicknessF = 2.0 ; thicken the box perimeter
  lgres@lgMonoDashIndex = True
  lgres@lgDashIndex = 0

  labels = (/"ISIMIP","MERRA","NCEP"/)
  nitems = dimsizes(labels) ; number of legend items
; Create legend
; lbid = gsn_create_legend(xwks,nitems,labels,lgres)
  lbid = gsn_create_legend(pwks,nitems,labels,lgres)
  ; Use gsn_add_annotation to attach this legend to our existing plot.
; This way, if we resize the plot, the legend will stay with the
; plot and be resized automatically.
;
  amres = True

;
; Point (0,0) is the dead center of the plot. Point (0,.5) is center,
; flush bottom. Point (0.5,0.5) is flush bottom, flush right.
;
  amres@amJust = "BottomRight" ; Use bottom right corner of box
                                            ; for determining its location.
  amres@amParallelPosF = 0.5 ; Move legend to right
  amres@amOrthogonalPosF = 0.5 ; Move legend down.

  annoid = gsn_add_annotation(plot,lbid,amres) ; add legend to plot

  psres = True

; maximize_output(xwks,psres) ; calls draw and frame for you
  maximize_output(pwks,psres)

There is no legend showing at all.

Could someone here to help me figure out where is the problem?

Thanks,

Ping

_______________________________________________
ncl-talk mailing list
List instructions, subscriber options, unsubscribe:
http://mailman.ucar.edu/mailman/listinfo/ncl-talk
Received on Mon Oct 15 16:44:11 2012

This archive was generated by hypermail 2.1.8 : Tue Oct 23 2012 - 11:10:04 MDT