## matplotlib-users

 [Matplotlib-users] Contour Plotting of Varied Data on a Shape From: Erik Schweller - 2009-08-21 16:12:58 Attachments: success.png     fail.png Hello all, This may be a difficult post to respond to in the whole, but any pointers would be appreciated. My overall goal is to generate contour plots for a wide range of input data. The data points are not regularly spaced and do not align to any grid. The data points represent measurements taken from a model that can take on a variety of shapes. To make matters more difficult, I'd prefer not to interpolate around corners of the model. For example ( please forgive the ascii art ): |-----------------------| | . . . . . . . .| | . . . . . . . .| |----------------| . . .| |. .| |. . .| |------| In the model above the edges denoted by "|" and "-", data points denoted by ".". This is a simple L shape with random data points sampled. For the most part, the approaches I've taken have worked, but I am hitting some difficult conditions to debug. Most unnerving are some artifacts in the plot even though the data values are fairly uniform (see attached image "fail.png" ). The general approach I'm taking goes as follows: 1 ) Make a linear space for the x and y components of the data and the model ( def_points_x is unique and sorted sorted in the code example ): # model boundary points x x_def = linspace( def_points_x[0], def_points_x[-1], self.num_points_x ) # do something similar for x and y of data and model points 2) Triangulate on the points try: ltri = delaunay.Triangulation( array( xPoints ), array( yPoints ) ) # xPoints and yPoints are data points except: ltri = ( None, None, None ) 3) use the natural neighbor extrapolator if extrapolate: # extrapolate try: interp_extrap = ltri.nn_extrapolator( region_values ) # values for the data points in same order ( i.e., ( xPoints[1], yPoints[1] ) -> region_values[1] ) except: return ( None, None, None) 4) extrapolate to the model boundary x2,y2 = meshgrid( x_def, y_def ) # model boundary region z = interp_extrap( x2, y2 ) 5) plot the result contourf( x_def, y_def, z, linspace( minValue, maxValue, self.numberOfContourLevels ), zorder = 50, extend = 'both' ) I've attached two images, one showing a nice result and one showing artifacts. Am I completely off base in this approach, hence I cannot seem to "perfect" the results? Suggestions? Thanks for reading! -Erik
 Re: [Matplotlib-users] Contour Plotting of Varied Data on a Shape From: Christopher Barker - 2009-08-22 05:46:10 Erik Schweller wrote: > My overall goal is to generate contour plots for a wide range of input > data. The data points are not regularly spaced and do not align to > any grid. The data points represent measurements taken from a model > that can take on a variety of shapes. To make matters more difficult, > I'd prefer not to interpolate around corners of the model. It strikes me that when you are working with unstructured data like this, it may be better to keep it unstrucured -- do the delanauy triangulation and directly contour from that. It's actually prety easy to contour a triangular mesh. Unfortunately, I haven't see code to do it in scipy or MPL. Am I wrong? Is there something there. If not, there really should be it seems a bit silly to shoehorn your data to a rectangular grid just to contour it. I suppose NN interpolation is essentially doing this already, but it introduces issues with a boundary that doesnt' line up to a rectangular grid. As I think about it, I'm going to have to write code to do this (contour an unstructured triangular mesh) sometime soon, so please let me know if it does exist already -- if not I'll try to remember to contribute it when I get around to it. -Chris -- Christopher Barker, Ph.D. Oceanographer Emergency Response Division NOAA/NOS/OR&R (206) 526-6959 voice 7600 Sand Point Way NE (206) 526-6329 fax Seattle, WA 98115 (206) 526-6317 main reception Chris.Barker@...
 Re: [Matplotlib-users] Contour Plotting of Varied Data on a Shape From: gely - 2010-03-08 20:20:13 Christopher Barker wrote: > > Erik Schweller wrote: >> My overall goal is to generate contour plots for a wide range of input >> data. The data points are not regularly spaced and do not align to >> any grid. The data points represent measurements taken from a model >> that can take on a variety of shapes. To make matters more difficult, >> I'd prefer not to interpolate around corners of the model. > > It strikes me that when you are working with unstructured data like > this, it may be better to keep it unstrucured -- do the delanauy > triangulation and directly contour from that. It's actually prety easy > to contour a triangular mesh. > > Unfortunately, I haven't see code to do it in scipy or MPL. Am I wrong? > Is there something there. If not, there really should be it seems a bit > silly to shoehorn your data to a rectangular grid just to contour it. > > I suppose NN interpolation is essentially doing this already, but it > introduces issues with a boundary that doesnt' line up to a rectangular > grid. > > As I think about it, I'm going to have to write code to do this (contour > an unstructured triangular mesh) sometime soon, so please let me know if > it does exist already -- if not I'll try to remember to contribute it > when I get around to it. > > -Chris > Chris, I found this old thread. Did you ever find code to directly interpolate a triangulation? I need to do the same thing. Thanks, Geoff -- Geoffrey Ely gely@... http://earth.usc.edu/~gely/ Department of Earth Sciences University of Southern California Los Angeles, CA 90089-0740 -- View this message in context: http://old.nabble.com/Contour-Plotting-of-Varied-Data-on-a-Shape-tp25089018p27826931.html Sent from the matplotlib - users mailing list archive at Nabble.com.
 Re: [Matplotlib-users] Contour Plotting of Varied Data on a Shape From: Chris Barker - 2010-03-11 21:49:12 Robert Kern wrote: >> the triangulation. Yes, it would use the existing delaunay code by >> default, and hopefully optionally use the not-as-good-a-license code the >> Robert Kern put in SciPy. > > I did what now? I thought you'd put a wrapper of a delaunay code that is GPL'd or something (not BSD compatible anyway) into a scikit or something? optional -- so it doesn't screw up licensing for those that don't want it. Anyway, the point is, for any code that might be put into MPL, we want a properly licensed compatible default, but ideally with the option of easily plug in in other, better, delaunay code that may not be license compatible. Now that I've written this, I really should go and look and see if I remember correctly: I've found this: http://scikits.appspot.com/delaunay Though I see no reference to license in there, so I presume it's under the same license as scipy. So I guess I was thinking of the natgrid toolkit, which I guess is not Robert's work, and is a substitute for nn interpolation, not triangulation. Sorry for writing too quickly. While I've got your attention, though -- I suspect you have looked for license compatible delaunay code and the stuff in the scikits package is as good as it gets? Thanks, -Chris -- Christopher Barker, Ph.D. Oceanographer Emergency Response Division NOAA/NOS/OR&R (206) 526-6959 voice 7600 Sand Point Way NE (206) 526-6329 fax Seattle, WA 98115 (206) 526-6317 main reception Chris.Barker@...