Re: warning:TransformPostDraw: tfPolyDrawList element 0 is invalid

From: Mary Haley <haley_at_nyahnyahspammersnyahnyah>
Date: Mon Apr 02 2012 - 09:20:34 MDT

Glad to hear you resolved this.

In case other people have the same problem, I'll include a possible solution.

Whenever you add polygons, polymarkers, polylines, or text to a plot using one of the gsn_add_xxxx functions, you have to make sure that the ids returned by these functions "live" for the duration of the script.

That is, you need to make sure that the ids returned don't get deleted before the script is done.

Since you are calling these functions inside a function, and variables local to a function are automatically deleted when the function is over, this means those ids are deleted.

To make sure the ids "live" outside the function, you can attach them as attributes to the return value:

 do t = 0, dimsizes(nps)-1
     centers(t) = gsn_add_polymarker(wks,plot,t+1,mean(t),polyres)
     error_bar(t) = gsn_add_polyline(wks,plot,(/t+1,t+1/),(/mean(t)-std(t),mean(t)+std(t)/),polyres)
 end do

 plot@centers = centers
 plot@error_bar = error_bar
 return(plot)

It doesn't matter what name you use for the attributes. Just make sure they are unique.

If this function is going to get called multiple times, then you can make sure the attribute names are unique every time:

 str1 = unique_string("centers")
 str2 = unique_string("error_bar")
 plot@$str1$ = centers
 plot@$str2$ = error_bar

The "unique_string" function will return a string like "centers0" the first time, and "centers1" the second time, etc.

--Mary

On Apr 1, 2012, at 10:01 AM, Cheung wrote:

>
> it's resolved, no need to bother.
>
> At 2012-04-01 21:58:13,Cheung <zuibeidemei@126.com> wrote:
> Dear all:
>
> I'm trying to add some error_bar to my plot. For efficiency, I use a function to do this.
>
> But the plot is generated without error bar, and it throws:
> warning:TransformPostDraw: tfPolyDrawList element 0 is invalid
> warning:TransformPostDraw: tfPolyDrawList element 1 is invalid
>
> .....
> plot(0) = add_error_bar(wks,res,6,mid,std)
> .. ...
>
> undef("add_error_bar")
> function add_error_bar(wks,res,nps:numeric,mean:numeric,std:numeric)
> begin
>
> plot = gsn_csm_xy(wks,ispan(1,6,1),mean(0:5),res)
> polyres &nbsp ; = True
> polyres@gsMarkerIndex = 1 ; index for circle
> polyres@gsMarkerSizeF = .01 ; size
> error_bar = new(nps,graphic)
> centers = new(nps,graphic)
> do t = 0, dimsizes(nps)-1
> centers(t) = gsn_add_polymarker(wks,plot,t+1,mean(t),polyres)
> error_bar(t) = gsn_add_polyline(wks,plot,(/t+1,t+1/),(/mean(t)-std(t),mean(t)+std(t)/),polyres)
> end do
> & ;nbs p; return(plot)
> end
>
> Thanks
>
>
>
>
>
>
> _______________________________________________
> ncl-talk mailing list
> List instructions, subscriber options, unsubscribe:
> http://mailman.ucar.edu/mailman/listinfo/ncl-talk

_______________________________________________
ncl-talk mailing list
List instructions, subscriber options, unsubscribe:
http://mailman.ucar.edu/mailman/listinfo/ncl-talk
Received on Mon Apr 2 09:20:49 2012

This archive was generated by hypermail 2.1.8 : Mon Apr 09 2012 - 13:43:03 MDT