[ncl-talk] Adding polylines to bar chart

Mary Haley haley at ucar.edu
Mon Oct 13 22:43:25 MDT 2014


There are a few things wrong with your code:


   - First, be sure to pay attention to any warnings or error messages
   coming out of NCL, as this may indicate what the problem is. I don't think
   your code should even be running as written, because you have some errors,
   which is my next bullet item:

   - gsn_add_polyline is a function, hence it needs to return a value:

id = gsn_add_polyline(....)


   - I recommend adding the polyline to the plot before you overlay it,
   because the nature of the plots change once they've been passed to the
   "overlay" call.

   - If a reference line is not showing up in a plot, it's likely because
   the values being used to draw the line are not in the same data space as
   the plot you are attaching it to.

   - I don't understand the coordinates of your line:


  xb0 =  (/0.4,0.4,0.4,0.4,0.4/)
 yb0 =  (/0.,0.,9.0,9.0,0.0/)

The X values are all the same, which indicates you are trying to draw a
vertical line. If this is the case, then you only need:

xb0   = (/0.4,0.4/)
yb0  = (/0, 9.0/)


   - Really, though, if you just need an X reference line, then see the
   special "gsnXRefLine" resource.


http://www.ncl.ucar.edu/Document/Graphics/Resources/gsn.shtml#gsnXRefLine

Please check all these issues and fix them.  If you still have problems, it
will help if you can provide the code and the data.

Thanks,

--Mary


On Mon, Oct 13, 2014 at 6:17 PM, Hyacinth Nnamchi <hyacinth.1 at hotmail.com>
wrote:

> Hi,
>
> I am trying to attach polyline to indicate some reference values in bar
> plots. The script runs without any error message and the bar chart plotted
> but without the polyline. The plot and script are attached. I appreciate
> any suggestions in advance.
>
> Thanks,
>
> Hyacinth
>
>   sres = True
>      sres at vpWidthF = 0.7
>      sres at vpHeightF = 0.5
>   ;   sres at trYLog = True
>      sres at vpXF = .15
>      sres at trXMinF = 0.4
>      sres at trXMaxF = 9.6
>      sres at trYMinF = -1.0
>      sres at trYMaxF = 1.0
>      sres at gsnYRefLine           = 0.0            ; create a reference
> line
>      sres at trXReverse            = True     ; Reverse X axis values
>      sres at gsnDraw = True
>      sres at gsnFrame = False
>      sres at tmXBLabelsOn  = True
>      sres at gsnXYBarChart = True
>      sres at gsnXYBarChartBarWidth = 0.15           ; change bar widths
>      sres at tmXBMode          = "Explicit"         ; explicit labels
>      sres at tmXBValues        = (/1,2,3,4,5,6,7,8,9/)
>      ;  sres at tmXBLabelDeltaF      = -45.0
>      sres at tmXBLabelAngleF         = 90.
>    ;  sres at tmXBDataLeftF           =  0.2
>      sres at tmXBMajorOutwardLengthF = 0.0               ; draw tickmarks
> inward
>      sres at tmXBMinorOutwardLengthF = 0.0               ; draw minor ticsk
> inward
>      sres at tmYLMajorOutwardLengthF = 0.0               ; draw tickmarks
> inward
>      sres at tmYLMinorOutwardLengthF = 0.0               ; draw minor ticsk
> inward
>      sres at tmXBLabelFontHeightF = 0.0150
>      sres at tmXTLabelFontHeightF = 0.0205
>      sres at tmYLLabelFontHeightF = 0.0225
>      sres at tiMainFontHeightF = 0.025
>      sres at tiMainFont = "helvetica"
>      sres at tiMainString = ""
>      sres at gsnRightString = ""
>      sres at tiYAxisString = "Correlation between (u'<MAM>) and (SST'<JJA>)"
>      sres at tiYAxisFontHeightF = 0.015
>
>      sres at gsnXYBarChartColors = (/"blue"/)
>      plot1 = gsn_csm_xy(wks,fspan(.775,8.775,9),rCL(0,:),sres)        ;
> draw each timeseries
>      sres at gsnXYBarChartColors = (/"lightpink"/)                    ;
> seperately, not
>      plot2 = gsn_csm_xy(wks,fspan(.925,8.905,9),rCL(1,:),sres)        ;
> advancing the frame
>     overlay(plot1,plot2)
>     plot(0) = plot1
> ;====================================================================
> ;========================================================================
> ;========================================================================
> ;========================================================================
> ; Create and add polylines @ 0.4
> ;========================================================================
> ;========================================================================
>   xb0 =  (/0.4,0.4,0.4,0.4,0.4/)
>  yb0 =  (/0.,0.,9.0,9.0,0.0/)
> ;========================================================================
> ;---Resources for the polyline
>   pres0                  = True           ; polyline mods desired
>   pres0 at gsLineThicknessF = 3.            ; line thickness
>   pres0 at gsLineColor      = "black"         ; color of lines
>   pres0 at gsLineDashPattern = 2
>
> ;---Attach the polyline
>
>   gsn_add_polyline(wks,plot(0),xb0,yb0,pres0)          ;
> ;**********************************************************
> ; add text labels
> ;**********************************************************
>   txres                     = True                 ; text mods desired
>   txres at txFontHeightF       = 0.018                ; default size is HUGE!
>  ; txres at txAngleF            = 52.                  ; text angle
>   txres at txJust              = "CenterLeft"         ; puts text on top of
> bars
>
> ;====================================================================
>      lbres                    = True         ; labelbar only resources
>      lbres at lbAutoManage       = False
>      lbres at vpWidthF           = 0.05          ; labelbar width
>      lbres at vpHeightF          = 0.08           ; labelbar height
>      lbres at lbBoxMajorExtentF  = 0.15          ; puts space between color
> boxes
>      lbres at lbFillColors       = (/"blue","lightpink"/)
>      lbres at lbMonoFillPattern  = True          ; Solid fill pattern
>      lbres at lbLabelFontHeightF = 0.015         ; font height. default is
> small
>      lbres at lbLabelJust        = "TopLeft"  ; left justify labels
>      lbres at lbPerimOn          = False
>      lbres at lgPerimColor      = "white"
>      labels = (/"Full-CGCM","Slab-CGCM"/)
>      gsn_labelbar_ndc(wks,1,labels,0.19,0.40,lbres)    ; draw right
> labelbar column
>
>      lbres at lbFillColors       = (/"lightpink","blue"/)
>      labels = (/"Slab-CGCM","Full-CGCM"/)
>      gsn_labelbar_ndc(wks,1,labels,0.50,0.40,lbres)    ; draw right
> labelbar column
>     ; labels = (/"CCSM2 (T42)","OBS        "/)
>     ; gsn_labelbar_ndc(wks,2,labels,0.17,0.23,lbres)    ; draw left
> labelbar column
> ;==============================================================
> frame(wks)
>
>
>
> _______________________________________________
> ncl-talk mailing list
> 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/20141013/7c9f5a94/attachment.html 


More information about the ncl-talk mailing list