[ncl-talk] Attache a legend and text to the plot

Anahita Amiri Farahani aamir003 at ucr.edu
Wed Feb 8 18:37:49 MST 2017


Hi All,

Here is my code to add legend and text to the plot, but it does not work:



m1 = "ccsm3_bgc4_I_11b"
m2 = "b30.061cb"

line_col1 = "red"
line_col2 = "blue"
line_pat1 = 0          ; Solid
line_pat2 = 2          ; Dashed


 wks   = gsn_open_wks ("eps","xy")
;---Set plotting parameters
 res                   = True
res at xyDashPattern  = 0                         ; Make curves all solid
res at xyLineColors      = (/"blue","red","green"/)          ; change line
color
res at tiMainString      = "Vertical profile of atmospheric heating rate"
        ; add title
res at tiXAxisString = "Atmospheric heating (K/day)"  ; xaxis string
res at tiYAxisString = "Pressure levels (hPa)"                  ; yaxis string
res at trYReverse        = True                       ; reverse Y-axis

res at trYMinF     = 0 ; set minimum Y-axis value
res at trYMaxF     =  1200 ; set maximum Y-axis value
res at trXMinF     = -0.5      ; set minimum X-axis value
res at trXMaxF     = 1.2      ; set maximum X-axis value


plot  = gsn_csm_xy (wks,data2,lev2,res) ; create plot
;
; Draw some text and lines to create a legend.
;
    res_text               = True
    res_text at txFontHeightF = 0.015
    res_text at txJust        = "CenterLeft"

    res_lines                   = True        ; polyline mods desired
    res_lines at gsLineColor       = line_col1   ; line color
    res_lines at gsLineThicknessF  = 3           ; line thicker
    res_lines at gsLineDashPattern = line_pat1   ; dash pattern

  xx = (/1893,1907/)
  yy = (/0.705,0.705/)
    gsn_polyline(wks,plot,xx,yy,res_lines)
    gsn_text(wks,plot,m1,1900,53.,res_text)

  yy = (/0.79,0.79/)
    res_lines at gsLineColor       = line_col2   ; line color
    res_lines at gsLineDashPattern = line_pat2   ; dash pattern
    gsn_polyline(wks,plot,xx,yy,res_lines)
    gsn_text(wks,plot,m2,1900,52.5,res_text)


delete(wks)





Thank you,
Ana
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20170208/277ae7ed/attachment.html 


More information about the ncl-talk mailing list