I've written some code to perform contouring on triangular grids. I
wrote the underlying C++ for a separate project, but as there has been
some interest on the mpl mailing lists for such functionality I've had
a go at wrapping it up as a python module so that it is available from
mpl. I've also added a few utility functions for plotting triangular
grids, doing pseudocolour plots, etc.
Attached is the source code with some documentation and examples.
There's an example of the output at
This example is similar to one of the mpl contourf examples, but on a
triangular grid of 1000 randomly spaced points, with the grid
So far it is only experimental code and hasn't been widely tested. I
have a list of improvements already, but thought it best to let people
see a working version before spending time polishing it. If it turned
out that a (much improved) version of it was considered good enough to
incorporate into mpl, I'd would happily help as I'd like to
I hope someone finds it useful!
From: Andrew Straw <strawman@as...> - 2009-09-18 16:30:21
Ian Thomas wrote:
> I've written some code to perform contouring on triangular grids. I
> wrote the underlying C++ for a separate project, but as there has been
> some interest on the mpl mailing lists for such functionality I've had
> a go at wrapping it up as a python module so that it is available from
> mpl. I've also added a few utility functions for plotting triangular
> grids, doing pseudocolour plots, etc.
Thanks for this.
I haven't had a chance to look at your code -- can you elaborate on the
approach you took versus natural neighbors interpolation, as available
through the mlab.griddata function? (See
examples/pylab_examples/griddata_demo.py for an example apparently
similar to yours.)
From: Christopher Barker <Chris.B<arker@no...> - 2009-09-18 16:44:11
Andrew Straw wrote:
> Thanks for this.
Yes, indeed. It looks like nice stuff!
I do encourage you to keep up the good work on this (the only thing I
notice is the need for some more docs). I also encourage you to keep the
contour generating code separate from anything matplotlib specific. I,
for one, would like to use it outside of MPL.
Unfortunately, it will probably be a month or two before I can spend any
time digging into this for my stuff, but it looks great so far.
> I haven't had a chance to look at your code -- can you elaborate on the
> approach you took versus natural neighbors interpolation, as available
> through the mlab.griddata function?
I think I can answer that a bit: this is contouring directly on the
triangular mesh, rather than interpolating to a rectangular grid, then
contouring. It should be a little more accurate, as well as saving
processing time and memory. In particular, it should work better around
the edges of a non-rectangular domain.
Christopher Barker, Ph.D.
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