[SciPyuser] SciPyuser 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: [SciPyuser] plotting a surface
 To: scipyuser@scipy.org
 Cc: jh@physics.ucf.edu
 MessageID: <1191315416.6370.780.camel@glup.physics.ucf.edu>
 ContentType: text/plain

 Or, you could just do it with matplotlib...

 http://physicsmajor.wordpress.com/2007/04/22/3dsurfacewithmatplotlib/

 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 SciPyuser
mailing list