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

URI zallen@urologicresearchinstitute....
Tue Feb 16 09:06:34 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 get these errors:

Traceback (most recent call last):
File "C:\Python26\Lib\site-packages\xy\plotscript_griddata.py", line 61, in
<module>
ax.plot_surface(x,y,z)
File "C:\Python26\lib\site-packages\mpl_toolkits\mplot3d\axes3d.py", line 573,
in plot_surface
rows, cols = Z.shape
ValueError: need more than 1 value to unpack

Maybe Mayavi is the way to go, I did come across it while researching this
problem.  I was worried that I couldn't install it alongside my current
installation, these things always seems to conflict with each other when I try
to have multiple packages installed.

"it's just more natural to top-post" - I completely agree.  I am using the web
interface to post so the admins have more control over what I'm doing.  Maybe I
should start using an email interface.

```

More information about the SciPy-User mailing list