[SciPy-user] SciPy-user Digest, Vol 50, Issue 3

James A. Bednar jbednar@inf.ed.ac...
Wed Oct 3 09:36:59 CDT 2007

|  Date: Tue, 02 Oct 2007 04:56:56 -0400
|  From: Joe Harrington <jh@physics.ucf.edu>
|  Subject: Re: [SciPy-user] plotting a surface
|  To: scipy-user@scipy.org
|  Cc: jh@physics.ucf.edu
|  Message-ID: <1191315416.6370.780.camel@glup.physics.ucf.edu>
|  Content-Type: text/plain
|  Or, you could just do it with matplotlib...
|  http://physicsmajor.wordpress.com/2007/04/22/3d-surface-with-matplotlib/
|  This was the first hit on a google search for "matplotlib surface".  I
|  tested it and it works in 0.90.1.

Interesting!  I couldn't find any documentation at all, but after some
hacking on that script I was able to make matplotlib 0.90.1 plot a
wireframe surface for a 2D numpy array, so I thought it could be
useful to include the code (below).

Note that the original example uses plot_surface instead of
plot_wireframe, but I've found plot_surface to be quite buggy, with
plots disappearing entirely much of the time, while plot_wireframe has
been reliable so far.  There is also contour3D, though that doesn't
look very useful yet.  Hopefully these 3D plots will all be polished
up a bit and made public in a new matplotlib release soon!


import pylab
from numpy import outer,arange,cos,sin,ones,zeros,array
from matplotlib import axes3d

def matrixplot3d(mat,title=None):
    fig = pylab.figure()
    ax = axes3d.Axes3D(fig)

    # Construct matrices for r and c values
    rn,cn = mat.shape
    c = outer(ones(rn),arange(cn*1.0))
    r = outer(arange(rn*1.0),ones(cn))


    if title: windowtitle(title)


More information about the SciPy-user mailing list