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

James A. Bednar jbednar at inf.ed.ac.uk
Wed Oct 3 10:36:59 EDT 2007


|  Date: Tue, 02 Oct 2007 04:56:56 -0400
|  From: Joe Harrington <jh at physics.ucf.edu>
|  Subject: Re: [SciPy-user] plotting a surface
|  To: scipy-user at scipy.org
|  Cc: jh at physics.ucf.edu
|  Message-ID: <1191315416.6370.780.camel at 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!

Jim
_______________________________________________________________________________

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))

    ax.plot_wireframe(r,c,mat)
        
    ax.set_xlabel('R')
    ax.set_ylabel('C')
    ax.set_zlabel('Value')

    if title: windowtitle(title)
    pylab.show()


matrixplot3d(array([[0.1,0.5,0.9],[0.2,0.1,0.0]]))



More information about the SciPy-User mailing list