[ncl-talk] Plotting polygons on xy plot

Mary Haley haley at ucar.edu
Thu Apr 20 17:30:42 MDT 2017


Hi Andrew,

You are close.

 In order for all the polygons to show up, the return value from
gsn_add_polygon must be unique.

You have the gsn_add_polygon call inside a double do loop, and inside of
the innermost loop you have:

    dum2 = new(dimsizes(temp_variable_3),graphic)

and then later:

    dum2(a) = gsn_add_polygon(wks,plot_without_ygrid,xbar,ybar,bres)

What's happening is that for each iteration of "a", dum2 is being reset to
an empty array. Any previous calls to gsn_add_polygon have been effectively
wiped out.

Also, given that you have two do loops, you will need to move this dum2
call to outside of both do loops and make it big enough to accommodate both
loops:

ntvar3 = dimsizes(temp_variable_3)
nregns = 5
dum2   = new((/nregns,ntvar3/),graphic)

do i=0,nregns-1 ; loop over regions
. . .

do a=0,ntvar3-1 ; loop over all values for this region

 . . .
 dum2(i,a) = gsn_add_polygon(wks,plot_without_ygrid,xbar,ybar,bres)
  . . .
end do
. . .
end do

Another way to do this that doesn't involve creating a "dum2" variable is
to use "unique_string" to create a unique name, and then use this unique
name as an attribute to any variable that holds the return value from
gsn_add_polygon. I usually use the "plot" variable:

 plot@$unique_string("polygon")$ =
gsn_add_polygon(wks,plot_without_ygrid,xbar,ybar,bres)


Hopefully by fixing this, your other issues with colors will resolve
themselves.

--Mary




On Thu, Apr 20, 2017 at 4:51 PM, Andrew Kren - NOAA Affiliate <
andrew.kren at noaa.gov> wrote:

> Dear ncl-talk,
>
> I am trying to plot a number of polygons on an xy plot, but for some
> reason, the polygons are not showing up. The only one that shows up is the
> last one. Also, the colors don't seem to work correctly, as they are all
> red and not varying based on my color array. The other problem is that the
> plot seems to be plotting twice and I can't figure out why. Attached is the
> figure and the program. The program is long so the only issue in the
> program starts at line 3148 and ends at 3209.
>
> Thanks much,
>
> --
> Andrew Kren, PhD
> Research Scientist I, Global Observing Systems Analysis (GOSA) Group
> NOAA ESRL Global Systems Division (Rm 3C515)
> 325 Broadway, Boulder, CO 80305
> (303) 497-5418
>
> _______________________________________________
> 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/20170420/1d3f3291/attachment.html 


More information about the ncl-talk mailing list