[ncl-talk] color set issue and label issue
Dave Allured - NOAA Affiliate
dave.allured at noaa.gov
Wed May 12 19:41:25 MDT 2021
1) For labels, you have one numeric array and one string array. Add the
special label after the numeric array is converted to strings, not before.
REG = (/1., 2., 3., 4., 5., 6., 7., 8., 9., 10./)
labels = "Region "+REG
labels(9) = "State Average"
2) You actually have 11 lines line this, when you should only have 10.
The last one is causing the error. It should simply be deleted.
res at xyLineColor = colors(10)
On Wed, May 12, 2021 at 4:31 PM Herb, Jason via ncl-talk <
ncl-talk at mailman.ucar.edu> wrote:
> Hello All,
>
> I am working on a plotting using overlays. I have 10 sets of data
> Regions#1-9 and an overall state average. I have two issues 1) The first
> when the labels for the region number are set up 1-9 and then try to set up
> to input the "State Average" into the labels NCL crashes saying it cannot
> deal with strings. How can I work around this issue?
> 2) I have 10 colors listed to set up the colors to be used and get the
> following errors.
> fatal:Subscript out of range, error in subscript #0
> fatal:An error occurred reading colors
> fatal:["Execute.c":8640]:Execute: Error occurred at or near line 113 in
> file COMonthlyRegionsingleplot.ncl
>
> res at xyLineColor = colors(10) I cannot understand why it is having
> this issue as it is the same as the other 9 items.
>
> The script is below
>
> Thank you
> Jason
>
> begin
>
> ;------- Load the associated file
> f0 = "COmonthly-Region.txt"
>
> data0 = asciiread(f0,(/12,11/),"double"); Region#1
>
> ;-------- Read the data loactions to the variable
> y0 = data0(:,1)
> y1 = data0(:,2)
> y2 = data0(:,3)
> y3 = data0(:,4)
> y4 = data0(:,5)
> y5 = data0(:,6)
> y6 = data0(:,7)
> y7 = data0(:,8)
> y8 = data0(:,9)
> y9 = data0(:,10)
>
> x0 = data0(:,0)
> y0 at _FillValue=integertoshort(-999)
> y1 at _FillValue=integertoshort(-999)
> y2 at _FillValue=integertoshort(-999)
> y3 at _FillValue=integertoshort(-999)
> y4 at _FillValue=integertoshort(-999)
> y5 at _FillValue=integertoshort(-999)
> y6 at _FillValue=integertoshort(-999)
> y7 at _FillValue=integertoshort(-999)
> y8 at _FillValue=integertoshort(-999)
> y9 at _FillValue=integertoshort(-999)
>
> colors =
> (/"red","green","blue","brown","orange","purple","gray","yellow","pink","black"/)
>
> REG = (/1., 2., 3., 4., 5., 6., .7, 8., 9., 10./)
> ;************************************************
> ; create plots
> ;************************************************
> plot = new(1,graphic)
>
> ;---Start the graphics
> wks = gsn_open_wks("png","COmonthly-Region2013-2018single.png")
> ; send graphics to PNG file
>
> ; resources for "left" variable
> res = True
>
> res at gsnMaximize = True
> res at gsnPaperOrientation = "portrait"
> res at gsnDraw = False
> res at gsnFrame = False
>
> res at trYMinF = 0 ; You could also just use
> res at trYMaxF = 1 ; min/max of u0,u1,u2.
>
> res at xyLineThicknessF = 2.0
>
> res at xyLineColor = colors(0)
>
> plot0 = gsn_csm_xy(wks,x0,y0,res)
>
> res at xyLineColor = colors(1)
> plot1 = gsn_csm_xy(wks,x0,y1,res)
>
> res at xyLineColor = colors(2)
>
> plot2 = gsn_csm_xy(wks,x0,y2,res)
>
> res at xyLineColor = colors(3)
>
> plot3 = gsn_csm_xy(wks,x0,y3,res)
> res at xyLineColor = colors(4)
>
> plot4 = gsn_csm_xy(wks,x0,y4,res)
> res at xyLineColor = colors(5)
>
> plot5 = gsn_csm_xy(wks,x0,y5,res)
> res at xyLineColor = colors(6)
>
> plot6 = gsn_csm_xy(wks,x0,y6,res)
>
> res at xyLineColor = colors(7)
>
> plot7 = gsn_csm_xy(wks,x0,y7,res)
> res at xyLineColor = colors(8)
>
> plot8 = gsn_csm_xy(wks,x0,y8,res)
> res at xyLineColor = colors(9)
>
> plot9 = gsn_csm_xy(wks,x0,y9,res)
> res at xyLineColor = colors(10)
>
> overlay(plot0,plot1)
> overlay(plot0,plot2)
> overlay(plot0,plot3)
> overlay(plot0,plot4)
> overlay(plot0,plot5)
> overlay(plot0,plot6)
> overlay(plot0,plot7)
> overlay(plot0,plot8)
> overlay(plot0,plot9)
>
>
> ;
> ; Attach a legend
>
> lgres = True
> lgres at lgLineColors = colors
> lgres at lgItemType = "Lines" ; show lines only (default)
> lgres at lgLabelFontHeightF = .08 ; legend label font thickness
> lgres at vpWidthF = 0.13 ; width of legend (NDC)
> lgres at vpHeightF = 0.10 ; height of legend (NDC)
> lgres at lgPerimThicknessF = 2.0 ; thicken the box perimeter
> lgres at lgMonoDashIndex = True
> lgres at lgDashIndex = 0
>
> labels = "Region"+REG
> legend = gsn_create_legend (wks, 10, 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.
> ;
> ; 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 = True
> amres at amJust = "BottomRight" ; Use bottom right corner of
> box
> ; for determining its location.
> amres at amParallelPosF = 0.5 ; Move legend to right
> amres at amOrthogonalPosF = 0.5 ; Move legend down.
>
> annoid = gsn_add_annotation(plot0,legend,amres) ; add legend to plot
>
> draw(plot0)
> frame(wks)
> end
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mailman.ucar.edu/pipermail/ncl-talk/attachments/20210512/aafe1ca3/attachment.html>
More information about the ncl-talk
mailing list