[ncl-talk] stack area plot
Mary Haley
haley at ucar.edu
Fri Mar 11 13:59:41 MST 2016
Hi Sitan,
What kind of stack plot are you trying to generate? You can look at our
"gsn_attach_plots" function. To see examples of using this, go to:
https://www.ncl.ucar.edu/Applications/func_list.shtml
and do a browser search on "gsn_attach_plots".
You may want to look at our panel examples page:
http://www.ncl.ucar.edu/Applications/panel.shtml
and search for the word "attach", which will lead you to some examples of
plots with shared axes borders.
You can also go to:
http://www.ncl.ucar.edu/Applications/xy.shtml
or
https://www.ncl.ucar.edu/Applications/concepts_list.shtml
and search for the word "stack".
----------------------
The issue with your script is that "dummy" and "dummy0" are variables that
are local to your "stack_area" function, and hence when you return from
that function, these variables go away. This means the attachments
disappear as well, and that's where the weird TransformPostDraw warning
comes from.
The fix is to attach the dummy ids to your "plotid" variable so they
continue to "live" outside of the "stack_area" function. You can either do
something like this:
plotid at dummy = dummy
plotid at dummy0 = dummy0
return(plotid)
or you can attach the return values directly when you call the gsn_add_xxxx
functions:
dummy = "gon" + ispan(1,ny,1)
plotid@$dummy(0)$ = gsn_add_polygon(wks,plotid,xbar,ybar,sres)
do i=1,ny-1
sres at gsFillColor=color(i)
y1 = dim_sum_n(data(:,0:i),1)
y2 = dim_sum_n(data(:,0:i-1),1)
ybar = array_append_record(y2,y1(::-1),0)
plotid@$dummy(i)$ = gsn_add_polygon(wks,plotid,xbar,ybar,sres)
end do
If you don't want to have to allocate "dummy" ahead of time, then you can
do something like this:
dumstr = unique_string("gon")
plotid@$dumstr$ = gsn_add_polygon(wks,plotid,xbar,ybar,sres)
do i=1,ny-1
sres at gsFillColor=color(i)
y1 = dim_sum_n(data(:,0:i),1)
y2 = dim_sum_n(data(:,0:i-1),1)
ybar = array_append_record(y2,y1(::-1),0)
dumstr = unique_string("gon")
plotid@$dumstr$ = gsn_add_polygon(wks,plotid,xbar,ybar,sres)
end do
--Mary
On Thu, Mar 10, 2016 at 3:35 PM, Sitan Heyl <heylsitan at gmail.com> wrote:
> Hi, All
> I am plotting a figure, which include four stack area plots. I wonder
> why NCL don't have stack plot function. if define a function to plot stack
> area, it is convenient when we need plot multiple this kind of figures. So
> I want to define stack_area function by myself, but it always met errors
> when transfer parameters like this.
>
> warning:TransformPostDraw: tfPolyDrawList element 0 is invalid
>
> any one can help?
> Best,
> Yongli
>
> _______________________________________________
> 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/20160311/0da0b63a/attachment.html
More information about the ncl-talk
mailing list