Re: gsn_add_polygon question

From: Mary Haley <haley_at_nyahnyahspammersnyahnyah>
Date: Mon, 13 Mar 2006 20:20:24 -0700

On Mar 13, 2006, at 10:27 AM, wrote:

> hi,
> I have an unusuall question...
> I have a file of x and y coordinates of a contour (on irregular grid).
> I managed to fill the contour with "gsn_add_polygon"
> .
> .
> .
> xy = gsn_xy(wks,x,y,res)
> .
> .
> .
> dum = gsn_add_polygon(wks, xy, x, y, gsres)
> .
> .
> .
> draw(xy)
> My question is, what is exactly xy after I call gsn_add_contour ? Is
> it an array of x and y coordinates of all the points inside the
> contour? If it is, I assume that the contour is somehow interpolated
> on a regular grid and then there is an algorithm to fill the points
> inside the contour. If so, what is the resolution of the grid? Can I
> controll it?
> If I'm completely wrong, is there a way in NCL to get such an array
> (array of x and y coordinates of all the points inside the contour)?
> Thanks,
> Roni


The "gsn_xy" function is a function that creates an XY plot given a
list of X and Y points. It has nothing to do with creating a contour
plot. Meanwhile, gsn_add_polygon is a function that creates a filled
polygon formed by points in X and Y, and "attaches" it to your XY plot.
By attaching it, that means if you redraw or resize the XY plot, your
polygon will get drawn along with the XY plot, or it will be resized
the same amount as your XY plot.

If what you really want are contours and not filled polygons, then you
should consider using "gsn_csm_contour". Normally gsn_csm_contour
expects a 2D array of data to contour, but if you give it a 1D array of
values you want to contour along with 1D arrays representing the
locations of your data to be contoured, then NCL will use a triangular
mesh interpolation (and not a grid interpolation) to generate the
contours. There are some examples of this on our Applications pages.
Please see the examples in the following URLs:

Note that the above examples are drawing contours over maps, but this
is not required in order to generate the contours. You would use the
same basic code, except don't set any map resources or use the
"_map_xxx" version of the "gsm_csm_xxx" routines.

If you actually want to interpolate your data to a grid before you
contour it, you can do this a number of ways. If you have X, Y, Z
coordinates, you can interpolate them to a 2D grid using triple2grid:

Or, you can use a nearest natural neighbor algorithm, "natgrid". See a
line-by-line description of using this routine to create a contour plot

Email me if this information doesn't help.

Good luck,


> _______________________________________________
> ncl-talk mailing list

ncl-talk mailing list
Received on Mon Mar 13 2006 - 20:20:24 MST

This archive was generated by hypermail 2.2.0 : Tue Mar 14 2006 - 08:36:27 MST