[ncl-talk] Setting missing value in table plot

Adam Phillips asphilli at ucar.edu
Fri Mar 19 16:37:52 MDT 2021


Hi Giorgio,
I do not have a feel for what the call to get_color_rgba returns in terms
of the dimension of the array. But you could check the output of the call
for missing values, and if present, set the color explicitly.
You could do something like this:
temp =
reshape(get_color_rgba(cmap,levels,data),(/product(dimsizes(data)),4/))
; use ind to check for missing values, and replace with a set of rgb values
w_ind = ind(ismissing(temp(0,:))
temp(:,w_ind) = (/0.5,0.5,0.5,0.5/)   ; set to gray50

gnres at gsColors  = temp

The above may not work as coded, but you should be able to apply the idea
after some trial and error.
If you have any further issues please respond to the ncl-talk email.
Good luck,
Adam


On Thu, Mar 18, 2021 at 11:55 AM Giorgio Graffino via ncl-talk <
ncl-talk at mailman.ucar.edu> wrote:

> Dear NCLers,
>
> I'm using NCL 6.6.2 on a Linux cluster. I'm adapting this script (
> https://www.ncl.ucar.edu/Applications/Scripts/table_8.ncl) to obtain
> something like the attached figure. It looks fine, but some of the white
> triangles are missing values while some aren't. I'm also getting these
> warnings:
>
> (0)     get_color_index: Error: More or more input values are missing.
> (0)         Returning missing.
> (0)     get_color_rgba: error: invalid input values. Returning missing.
>
> The relevant function for drawing the plot is the following:
>
> undef("add_filled_triangles")
> procedure add_filled_triangles(wks,plot,data,levels,cmap,location)
> local dims, gnres, nc, nr, nrow, ncol, xtri, ytri, xtri2d, ytri2d, irows, icols
> begin
>   dims = dimsizes(data)
>   nrow = dims(0)
>   ncol = dims(1)
>   ytri2d = new((/nrow,4/),float)
>   xtri2d = new((/ncol,4/),float)
>
>   irows = ispan(0,nrow-1,1)
>   icols = ispan(0,ncol-1,1)
>   if(location.eq."bot") then
>     xtri2d(:,0) = icols
>     xtri2d(:,1) = icols+1.0
>     xtri2d(:,2) = icols+0.5
>     xtri2d(:,3) = icols
>     ytri2d(:,0) = irows
>     ytri2d(:,1) = irows
>     ytri2d(:,2) = irows+0.5
>     ytri2d(:,3) = irows
>   else if(location.eq."top") then
>     xtri2d(:,0) = icols
>     xtri2d(:,1) = icols+1.0
>     xtri2d(:,2) = icols+0.5
>     xtri2d(:,3) = icols
>     ytri2d(:,0) = irows+1
>     ytri2d(:,1) = irows+1
>     ytri2d(:,2) = irows+0.5
>     ytri2d(:,3) = irows+1
>   else if(location.eq."lft") then
>     xtri2d(:,0) = icols
>     xtri2d(:,1) = icols
>     xtri2d(:,2) = icols+0.5
>     xtri2d(:,3) = icols
>     ytri2d(:,0) = irows
>     ytri2d(:,1) = irows+1.0
>     ytri2d(:,2) = irows+0.5
>     ytri2d(:,3) = irows
>   else
>     xtri2d(:,0) = icols+1
>     xtri2d(:,1) = icols+1
>     xtri2d(:,2) = icols+0.5
>     xtri2d(:,3) = icols+1
>     ytri2d(:,0) = irows
>     ytri2d(:,1) = irows+1
>     ytri2d(:,2) = irows+0.5
>     ytri2d(:,3) = irows
>   end if
>   end if
>   end if
>   xtri = conform_dims((/nrow,ncol,4/),xtri2d,(/1,2/))
>   ytri = conform_dims((/nrow,ncol,4/),ytri2d,(/0,2/))
>
>   gnres            = True                     ; resource list for filled polygons
>   gnres at gsEdgesOn  = True                     ; outline each filled triangle
>   gnres at gsSegments = ispan(0,nrow*ncol*4,4)   ; this makes code faster
>
> ;--If you have NCL V6.4.0 or older, you must use the "_mod" version of the function
> ; gnres at gsColors   = reshape(get_color_rgba_mod(cmap,levels,data),(/product(dimsizes(data)),4/))
>
> ;---This will only work in NCL V6.5.0 or later.
>   gnres at gsColors   = reshape(get_color_rgba(cmap,levels,data),(/product(dimsizes(data)),4/))
>
>   tmpstr = unique_string(location)
>   plot@$tmpstr$ = gsn_add_polygon(wks,plot,ndtooned(xtri),ndtooned(ytri),gnres)
> end
>
> I tried including a resource like gnres at gsFillBackgroundColor = "Grey" to change the background color, but nothing changed. Do you know how I can set a specific color (different than white or transparent) for missing values in that function?
>
> Thanks a lot,
>
> Giorgio
>
> _______________________________________________
> ncl-talk mailing list
> ncl-talk at mailman.ucar.edu
> List instructions, subscriber options, unsubscribe:
> https://mailman.ucar.edu/mailman/listinfo/ncl-talk



-- 
Adam Phillips
Associate Scientist,  Climate and Global Dynamics Laboratory, NCAR
www.cgd.ucar.edu/staff/asphilli/   303-497-1726

<http://www.cgd.ucar.edu/staff/asphilli>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mailman.ucar.edu/pipermail/ncl-talk/attachments/20210319/79e8de14/attachment.html>


More information about the ncl-talk mailing list