[SciPy-User] creating a 3D surface plot from collected data

URI zallen@urologicresearchinstitute....
Tue Feb 16 11:57:50 CST 2010


Joe Kington <jkington <at> wisc.edu> writes:

> 
> 
> No worries about the bottom post. I actually think I'm breaking protocol by
top-posting, but I use gmail, and it's just more natural to top-post.Anyway, I
think your problem is coming from the fact that you're working with an
isosurface that fully encloses a volume. I assumed that you had scattered data
points (say, elevation measurements) that you needed to interpolate between. 
The interpolation example I posted implicitly assumes that z = f(x,y). In other
words, that there is only one z value for any given x and y.  If you're working
with a 3D kidney-shape, this is clearly not the case.  Therefore, you're getting
a singluar matrix when you try to interpolate (more than one value of z for
identical rows of x and y in the matrix).The good news is that this may make the
problem much simpler. (Your data is already in some sort of triangle-strip
format if it's been exported from an imaging program. No need to
interpolate.)What happens when you just do:fig = plt.figure()ax =
Axes3D(fig)ax.plot_surface(x,y,z)plt.show()Where x,y,z are your raw data? 
There's a reasonable chance that the program you used to export the x,y,z
isosurface left the verticies in the order that plot_surface expects them
in...On a side note, you might also look into Mayavi's mlab module for 3D
plotting.  I prefer it to matplotlib's native 3D plotting. If you have it
installed, you'd just do:from enthought.mayavi import mlabs = mlab.mesh(x, y,
z)mlab.show()Hope that helps some,
> -Joe

I understand what you mean about assuming that z is a proper function of x and
y, but after looking again at the examples on the tutorial page
(http://matplotlib.sourceforge.net/mpl_toolkits/mplot3d/tutorial.html#getting-started)
I remember why I thought plot_surface was the proper function: the second
example under the plot_surface heading shows a spherical surface, so I figured
plot_surface didn't assume a 1-to-1 relationship.



More information about the SciPy-User mailing list