[ncl-talk] ExcludeOuterBoxes in gsn_create_labelbar

Giorgio Graffino g.graffino at tim.it
Wed Oct 5 08:40:28 MDT 2022


Hi Adam,

Thanks for the suggestion. I wasn't familiar with lbLabelAlignment. I 
adapted the last part of 
https://www.ncl.ucar.edu/Applications/Scripts/lb_14.ncl in the 
add_labelbar function. Now it looks like below, although I'm getting an 
error message.

fatal:["NclAtt.c":262]:Attribute assignment type mismatch.

I don't know from which part of the function the message is coming. The 
labelbar is correctly changed despite the message.

Cheers,
Giorgio

undef("add_labelbar")
procedure add_labelbar(wks,plot,cmap,labels,stride,title,location)
local nboxes, nlabel, vph, vpw, lbres, lbid, amres, annoid
begin
   nlabel = dimsizes(labels)
   nboxes = dimsizes(labels)+1
   colors = span_color_rgba(cmap,nboxes)
   getvalues plot                      ; Get plot size for use in
     "vpHeightF" : vph                 ; creating labelbar.
     "vpWidthF"  : vpw
   end getvalues
;
; Set some resources for a vertical or horizontal labelbar on the
; bottom or right axis.
;
; am_para/am_orth
;    0.0/ 0.0  -  annotation in dead center of plot
;    0.5/ 0.5  -  annotation at bottom right of plot
;    0.5/-0.5  -  annotation at top right of plot
;   -0.5/-0.5  -  annotation at top left of plot
;   -0.5/ 0.5  -  annotation at bottom left of plot
;
; You will likely need to modify the am_para/am_orth
; values depending on your X and Y axis labels, the size
; of your plot, the number of rows and columns you have, et.
;
   if(any(location.eq.(/"bot1","bot2"/))) then
     orient  = "horizontal"
     width   = vpw * 0.95   ; slightly shorter than width of plot
     height  = vph * 0.15
     am_just = "BottomCenter"
     am_para = 0.0         ; Centered about X axis
     title_pos = "Top"
     if(location.eq."bot1")
       am_orth = 0.85       ; Move labelbar down
     else
       am_orth = 1.04       ; Move further down
     end if
   else
     orient  = "vertical"
     width   = vpw * 0.15
     height  = vph * 0.95    ; Slightly shorter than height of plot
     am_just = "TopLeft"
     am_orth = -0.5          ; Move labelbar up
     title_pos = "Left"
     if(location.eq."rgt2")
       am_para = 0.55        ; Move labelbar right
     else
       am_para = 0.78        ; Move further right
     end if
   end if
; labelbar resources
   lbres                    = True
   lbres at lbAutoManage       = False         ; Necessary to control sizes
   lbres at vpWidthF           = width
   lbres at vpHeightF          = height
   lbres at lbFillColors       = colors        ; Labelbar colors
   lbres at lbMonoFillPattern  = True          ; Solid fill pattern
   lbres at lbLabelFontHeightF = 0.015         ; Font height, default is 
small
;  lbres at lbLabelAlignment   = "InternalEdges"
   lbres at lbOrientation      = orient
   lbres at lbTitleString      = title
   lbres at lbPerimOn          = False
   lbres at lbTitlePosition    = title_pos
   lbres at lbLabelStride      = stride
; this part is to exclude the boxes outside the range of labels (adapted 
from https://www.ncl.ucar.edu/Applications/Scripts/lb_14.ncl)
   lbres at lbLabelAlignment   = "ExternalEdges"
   labels_plus              = 
new(nlabel+2,typeof(labels),labels at _FillValue)
   labels_plus(1:nlabel)    = labels
   labels_plus(0)           = labels(0)
   labels_plus(nlabel+1)    = labels(nlabel-1)
   lbres at lbLabelStrings     = sprintf("%5.1f",labels_plus)

   lbid = gsn_create_labelbar(wks,nboxes,labels_plus,lbres)
; annotation resources
   amres                  = True
   amres at amJust           = am_just
   amres at amOrthogonalPosF = am_orth
   amres at amParallelPosF   = am_para
; attach the labelbar to the plot
   plot at annoid = gsn_add_annotation(plot,lbid,amres)
end



    ------ Messaggio Originale ------
    Da: asphilli at ucar.edu
    A: g.graffino at tim.it
Cc: ncl-talk at ucar.edu
    Inviato: martedì 4 ottobre 2022 17:53
    Oggetto: Re: [ncl-talk] ExcludeOuterBoxes in gsn_create_labelbar


Hi Giorgio,
You can try setting lbLabelAlignment to "ExternalEdges" which I believe 
will produce the same results as cnLabelBarEndStyle. See example #14 
here:
https://www.ncl.ucar.edu/Applications/labelbar.shtml#ex14
  <https://www.ncl.ucar.edu/Applications/labelbar.shtml#ex14>
Or see many other examples where this resource is set:
https://www.ncl.ucar.edu/Applications/res_list.shtml#lbLabelAlignment 
<https://www.ncl.ucar.edu/Applications/res_list.shtml#lbLabelAlignment>

Hope that helps!
Adam


On Wed, Sep 28, 2022 at 1:22 PM Giorgio Graffino via ncl-talk 
<ncl-talk at mailman.ucar.edu <mailto:ncl-talk at mailman.ucar.edu> > wrote:

Dear NCL Community,

I'm trying to set the resource cnLabelBarEndStyle to "ExcludeOuterBoxes" 
while calling gsn_create_labelbar, to get ride of the labelbar boxes 
bigger than 1 and smaller than -1 in the attached plot. However, since 
I'm not drawing a contour plot, the resource doesn't do anything. I'm 
adapting this example 
(https://www.ncl.ucar.edu/Applications/Scripts/table_8.ncl 
<https://www.ncl.ucar.edu/Applications/Scripts/table_8.ncl> ). The 
procedure drawing the labelbar is shown below.

How can I solve the issue? I tried to look for a solution in the quick 
search bar in https://www.ncl.ucar.edu/Support/posting_guidelines.shtml 
<https://www.ncl.ucar.edu/Support/posting_guidelines.shtml> , but it's 
always giving me the following error "The requested page could not be 
found."

Cheers,
Giorgio

undef("add_labelbar")
procedure add_labelbar(wks,plot,cmap,labels,stride,title,location)
local nboxes, vph, vpw, nboxes, lbres, lbid, amres, annoid
begin
   nboxes = dimsizes(labels)+1
   colors = span_color_rgba(cmap,nboxes)
   getvalues plot                      ; Get plot size for use in
     "vpHeightF" : vph                 ; creating labelbar.
     "vpWidthF"  : vpw
   end getvalues
;
; Set some resources for a vertical or horizontal labelbar on the
; bottom or right axis.
;
; am_para/am_orth
;    0.0/ 0.0  -  annotation in dead center of plot
;    0.5/ 0.5  -  annotation at bottom right of plot
;    0.5/-0.5  -  annotation at top right of plot
;   -0.5/-0.5  -  annotation at top left of plot
;   -0.5/ 0.5  -  annotation at bottom left of plot
;
; You will likely need to modify the am_para/am_orth
; values depending on your X and Y axis labels, the size
; of your plot, the number of rows and columns you have, et.
;
   if(any(location.eq.(/"bot1","bot2"/))) then
     orient  = "horizontal"
     width   = vpw * 0.95   ; slightly shorter than width of plot
     height  = vph * 0.15
     am_just = "BottomCenter"
     am_para = 0.0         ; Centered about X axis
     title_pos = "Top"
     if(location.eq."bot1")
       am_orth = 0.85       ; Move labelbar down
     else
       am_orth = 1.04       ; move further down
     end if
   else
     orient  = "vertical"
     width   = vpw * 0.15
     height  = vph * 0.95    ; slightly shorter than height of plot
     am_just = "TopLeft"
     am_orth = -0.5          ; Move labelbar up
     title_pos = "Left"
     if(location.eq."rgt2")
       am_para = 0.55        ; Move labelbar right
     else
       am_para = 0.78        ; move further right
     end if
   end if
; labelbar resources
   lbres                    = True
   lbres at lbAutoManage       = False         ; Necessary to control sizes
   lbres at vpWidthF           = width
   lbres at vpHeightF          = height
   lbres at cnLabelBarEndStyle = "ExcludeOuterBoxes"
   lbres at lbFillColors       = colors        ; labelbar colors
   lbres at lbMonoFillPattern  = True          ; Solid fill pattern
   lbres at lbLabelFontHeightF = 0.015          ; font height. Default is 
small
   lbres at lbLabelAlignment   = "InteriorEdges"
   lbres at lbOrientation      = orient
   lbres at lbTitleString      = title
   lbres at lbPerimOn          = False
   lbres at lbTitlePosition    = title_pos
   lbres at lbLabelStride      = stride
   lbid = gsn_create_labelbar(wks,nboxes,labels,lbres)
; annotation resources
   amres                  = True
   amres at amJust           = am_just
   amres at amOrthogonalPosF = am_orth
   amres at amParallelPosF   = am_para
; attach the labelbar to the plot
   plot at annoid = gsn_add_annotation(plot,lbid,amres)
end_______________________________________________
  ncl-talk mailing list
  ncl-talk at mailman.ucar.edu <mailto:ncl-talk at mailman.ucar.edu>
  List instructions, subscriber options, unsubscribe:
  https://mailman.ucar.edu/mailman/listinfo/ncl-talk 
<https://mailman.ucar.edu/mailman/listinfo/ncl-talk>



-- 





Adam Phillips
Associate Scientist IV, Climate Analysis Section
Climate and Global Dynamics Laboratory

National Center for Atmospheric Research

www.cgd.ucar.edu/staff/asphilli/ 
<http://www.cgd.ucar.edu/staff/asphilli/>


  <http://www.cgd.ucar.edu/staff/asphilli>









-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mailman.ucar.edu/pipermail/ncl-talk/attachments/20221005/337d88b3/attachment.htm>


More information about the ncl-talk mailing list