[ncl-talk] how to add horizontal constant lines to a plot

Rick Brownrigg brownrig at ucar.edu
Fri Mar 31 10:36:10 MDT 2017


Hi Anahita,

Just to follow up on this, my colleague Mary has added some examples of how
to draw reference lines, which are much easier and cleaner than the code I
suggested. Check out examples 36/36_vref  at:

http://www.ncl.ucar.edu/Applications/xy.shtml#ex36

Thanks Mary!

Rick


On Thu, Mar 30, 2017 at 7:44 AM, Rick Brownrigg <brownrig at ucar.edu> wrote:

>
> HI,
>
> One way would be to use gsn_add_polyline():
>
>     http://ncl.ucar.edu/Document/Graphics/Interfaces/gsn_add_
> polyline.shtml
>
> In short after each plot, you'd set up the line resources the way you
> want, and call this function 3 times for each plot for each of the three
> altitudes.  Note that you need to assign the results returned by the
> function to a unique variable, as the lines (nor the plots) aren't actually
> drawn until the call to gsn_panel.  So, for the first plot, something like:
>
>    ; these 3 lines done once...
>    lines = new((/12/), graphic)   ; variable to hold the 12 lines
>    lnres = True
>    lnnum = 0
>
>    plot(0) = gsn_csm_xy(......)
>    lnres at gsLineColor = "red"
>    lnres at gsLineDashPattern = ...
>    lines(lnnum) = gsn_add_polyline(wks, plot(0), (/res at trXMinF,
> res at trXMaxF/), (/1., 1./), lnres)
>    lnnum = lnnum + 1
>
>    lnres at gsLineColor = "blue
>    lnres at gsLineDashPattern = ...
>    lines(lnnum) = gsn_add_polyline(wks, plot(0), (/res at trXMinF,
> res at trXMaxF/), (/2., 2./), lnres)
>    lnnum = lnnum + 1
>
>    lnres at gsLineColor = "green"
>    lnres at gsLineDashPattern = ...
>    lines(lnnum) = gsn_add_polyline(wks, plot(0), (/res at trXMinF,
> res at trXMaxF/), (/3., 3./), lnres)
>    lnnum = lnnum + 1
>
> And so on. This is a bit tedious, and there are other ways to structure
> this, eg, you could draw all the plots, then add the lines looping over the
> plots, etc.  I'd probably turn the line drawing part into a function,
> passing in the colors, patterns, wks, and plot number, returning the line
> result.
>
> Hope that helps...
> Rick
>
> On Wed, Mar 29, 2017 at 10:17 PM, Anahita Amiri Farahani <aamir003 at ucr.edu
> > wrote:
>
>> Hello all,
>>
>> I want to add three horizontal constant lines (solid and dashed) at
>> different altitudes (1,2, and 3 km) with different colors to my plot but I
>> don't know how to do it. I have attached the figure and the code.
>>
>>
>>
>>
>>  wks = gsn_open_wks("eps","vertical_whole")
>> ; gsn_define_colormap(wks,"gui_default")
>>  plot = new(4,graphic)
>> ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
>>   res                     = True               ; plot mods desired
>> res at gsnFrame        = False   ; don't draw yet
>>  res at gsnDraw         = False   ; don't advance frame yet
>>
>> res at tiXAxisString = "Dust extinction coefficient"  ; xaxis string
>>   res at tiYAxisString = "Altitude (km)"                  ; yaxis string
>> ;res at trYReverse        = True                       ; reverse Y-axis
>>
>>   res at trYMinF     = -1 ; set minimum Y-axis value
>>   res at trYMaxF     =  10 ; set maximum Y-axis value
>>   res at trXMinF     = 0        ; set minimum X-axis value
>>   res at trXMaxF     = 0.06       ; set maximum X-axis value
>>
>>
>> ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
>>
>> res at gsnLeftString       = "Winter"         ; change left string
>> plot(0) = gsn_csm_xy(wks,extinct_winter_avg2,alt,res)
>> res at gsnLeftString       = "Spring"         ; change left string
>> plot(1) = gsn_csm_xy(wks,extinct_spring_avg2,alt,res)
>> res at gsnLeftString       = "Summer"         ; change left string
>> plot(2) = gsn_csm_xy(wks,extinct_summer_avg2,alt,res)
>> res at gsnLeftString       = "Fall"         ; change left string
>> plot(3) = gsn_csm_xy(wks,extinct_fall_avg2,alt,res)
>> ;************************************************
>> ; create panel
>> ;************************************************
>> resP                  = True                    ; modify the panel plot
>>
>>  resP at gsnPanelFigureStrings = (/"a)","b)","c)","d)"/)      ; add strings
>> to panel
>>  gsn_panel(wks,plot,(/2,2/),resP)
>>
>>
>> delete(plot)
>> delete(res)
>> delete(resP)
>> delete(wks)
>>
>>
>>
>>
>> Thanks,
>> 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/20170331/2a883a6b/attachment.html 


More information about the ncl-talk mailing list