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

Anahita Amiri Farahani aamir003 at ucr.edu
Thu Feb 9 12:18:30 MST 2017


I tried res at gsnDraw = False, but it didn't work. here is my code:


m1 = "No Aerosol" m2 = "All Aerosols" 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 gsnDraw = False ;
don't draw the plots now res at gsnFrame = False ; or advance the frame
res at tmYROn = False ; Don't draw labels for res at tmYRLabelsOn = False ; right
Y axes, b/c left 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) draw(plot) delete(wks)
Thanks,
Ana



On Thu, Feb 9, 2017 at 8:40 AM, Rick Brownrigg <brownrig at ucar.edu> wrote:

> HI,
>
> Normally, when you make calls that return a plot object, such as
> gsn_csm_xy(), the plot is generated and drawn immediately.  If you want to
> further annotate the plot with polylines or text, etc, you have to suppress
> this auto-draw:
>
>  res at gsnDraw  = False       ; don't draw the plots now
>  res at gsnFrame = False       ; or advance the frame
>  ...
>
>  plot = gsn_csm_xy(wks, ...., res)
>  ...
>
>  gsn_ployline(...)
>
>  gsn_text(...)
>
>  ...etc...
>
>  draw(plot)    ; now explicitly draw the plot
>
>  frame(wks)    ; advance workstaton to next page/window/image
>  ...
>
> Make sense?
>
> Rick
>
>
> On Wed, Feb 8, 2017 at 6:37 PM, Anahita Amiri Farahani <aamir003 at ucr.edu>
> wrote:
>
>> 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
>>
>> _______________________________________________
>> ncl-talk mailing list
>> ncl-talk at ucar.edu
>> List instructions, subscriber options, unsubscribe:
>> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20170209/6cb6cea8/attachment.html 


More information about the ncl-talk mailing list