Contour plots [Was: Re: how to make matplotlib faster?]

I use Hardy's multiquadric interpolation to to do the math,

    > then use imshow (or pcolor) to make a surface map. I only
    > have data for the 120 points (where the circle are - those
    > are actuators), and interpolate the rest.

    > If people are interested, I can clean up the code a little
    > and post it.

This sounds pretty close to matlab's griddata function. It would be
very nice to have this in matplotlib.mlab, perhaps as a wrapper to
some core scipy functionality, which could be conditionally imported.
What requirements does your code have -- pure python, extension code,
scipy, numarray?

Here is the matlab docstring, FYI

GRIDDATA Data gridding and surface fitting.
    ZI = GRIDDATA(X,Y,Z,XI,YI) fits a surface of the form Z = F(X,Y)
    to the data in the (usually) nonuniformly-spaced vectors (X,Y,Z)
    GRIDDATA interpolates this surface at the points specified by
    (XI,YI) to produce ZI. The surface always goes through the data
    points. XI and YI are usually a uniform grid (as produced by
    MESHGRID) and is where GRIDDATA gets its name.
  
    XI can be a row vector, in which case it specifies a matrix with
    constant columns. Similarly, YI can be a column vector and it
    specifies a matrix with constant rows.
  
    [XI,YI,ZI] = GRIDDATA(X,Y,Z,XI,YI) also returns the XI and YI
    formed this way (the results of [XI,YI] = MESHGRID(XI,YI)).
  
    [...] = GRIDDATA(...,'method') where 'method' is one of
        'linear' - Triangle-based linear interpolation (default).
        'cubic' - Triangle-based cubic interpolation.
        'nearest' - Nearest neighbor interpolation.
        'v4' - MATLAB 4 griddata method.
    defines the type of surface fit to the data. The 'cubic' and 'v4'
    methods produce smooth surfaces while 'linear' and 'nearest' have
    discontinuities in the first and zero-th derivative respectively. All
    the methods except 'v4' are based on a Delaunay triangulation of the
    data.
  
    See also GRIDDATA3, GRIDDATAN, DELAUNAY, INTERP2, MESHGRID.

John Hunter wrote:

> I use Hardy's multiquadric interpolation to to do the math,
> then use imshow (or pcolor) to make a surface map. I only
> have data for the 120 points (where the circle are - those
> are actuators), and interpolate the rest.

> If people are interested, I can clean up the code a little
> and post it.

This sounds pretty close to matlab's griddata function.

Yup. That's the functionality I needed. As it says in MATLAB docstrig below, GRIDDATA uses Delaunay triangulation however.

It would be
very nice to have this in matplotlib.mlab, perhaps as a wrapper to
some core scipy functionality, which could be conditionally imported.
What requirements does your code have -- pure python, extension code,
scipy, numarray?

The interpolating is done all in python with the use of Numeric (this is what I have been using, and what my matplotlib installation uses - maybe will upgrade to numarray one of these days). Performance wise, It's not very practical for a very large number of points N as it has to solve a NxN system (my N=120 and takes ~2.3seconds on a P4 3.2Ghz with 2GB ram - cant remember how long MATLAB's griddata took). Maybe numarray would be faster?!

The drawing of the mirror, actuators, etc is done using matplotlibs imshow(), plot() and fill() - all very straight forward.

I will post the code in the next few days when I have a minute to clean it up a litte.

Cheers,

···

--
Peter Groszkowski Gemini Observatory
Tel: +1 808 9742509 670 N. A'ohoku Place
Fax: +1 808 9359235 Hilo, Hawai'i 96720, USA

Here is the matlab docstring, FYI

GRIDDATA Data gridding and surface fitting.
ZI = GRIDDATA(X,Y,Z,XI,YI) fits a surface of the form Z = F(X,Y)
to the data in the (usually) nonuniformly-spaced vectors (X,Y,Z)
GRIDDATA interpolates this surface at the points specified by
(XI,YI) to produce ZI. The surface always goes through the data
points. XI and YI are usually a uniform grid (as produced by
MESHGRID) and is where GRIDDATA gets its name.

XI can be a row vector, in which case it specifies a matrix with
constant columns. Similarly, YI can be a column vector and it
specifies a matrix with constant rows.

[XI,YI,ZI] = GRIDDATA(X,Y,Z,XI,YI) also returns the XI and YI
formed this way (the results of [XI,YI] = MESHGRID(XI,YI)).

[...] = GRIDDATA(...,'method') where 'method' is one of
'linear' - Triangle-based linear interpolation (default).
'cubic' - Triangle-based cubic interpolation.
'nearest' - Nearest neighbor interpolation.
'v4' - MATLAB 4 griddata method.
defines the type of surface fit to the data. The 'cubic' and 'v4'
methods produce smooth surfaces while 'linear' and 'nearest' have
discontinuities in the first and zero-th derivative respectively. All
the methods except 'v4' are based on a Delaunay triangulation of the
data.

See also GRIDDATA3, GRIDDATAN, DELAUNAY, INTERP2, MESHGRID.