Problem using plot_surface.

Hi, I have three variables I would like to plot using plot_surface but I keep getting the error given at the bottom. Anyone know what I am doing wrong?? My code is as follows,

fig3 = plt.figure()
ax = Axes3D(fig3)
X = np.zeros((78,1))
Y = np.zeros((78,1))
Z = np.zeros((78,1))
for p in range(len(data)):
     X[p,0] = data[p][1] #distance
     Y[p,0] = data[p][3] #azimuth
     Z[p,0] = data[p][4] #snr
X, Y = np.meshgrid(X, Y)
surf = ax.plot_surface(X, Y, Z, rstride=1, cstride=1, cmap=cm.jet)

ValueError Traceback (most recent call last)

/home/davcra/python_scripts/plot_snr_az.py in <module>()
      48 Z[p,0] = data[p][4] #snr
      49 X, Y = np.meshgrid(X, Y)
---> 50 surf = ax.plot_surface(X, Y, Z, rstride=1, cstride=1, cmap=cm.jet)
      51 #fig.colorbar(surf, shrink=0.5, aspect=5)

      52 #plt.show()

/usr/lib64/python2.6/site-packages/mpl_toolkits/mplot3d/axes3d.pyc in plot_surface(self, X, Y, Z, *args, **kwargs)
     616 normals.append(np.cross(v1, v2))
     617
--> 618 polyc = art3d.Poly3DCollection(polys, *args, **kwargs)
     619 if cmap is not None:
     620 polyc.set_array(np.array(avgz))

/usr/lib64/python2.6/site-packages/mpl_toolkits/mplot3d/art3d.pyc in __init__(self, verts, *args, **kwargs)
     282 '''
     283
--> 284 PolyCollection.__init__(self, verts, *args, **kwargs)
     285 self._zsort = 1
     286 self._sort_zpos = None

/usr/lib64/python2.6/site-packages/matplotlib/collections.pyc in __init__(self, verts, sizes, closed, **kwargs)
     666 Collection.__init__(self,**kwargs)
     667 self._sizes = sizes
--> 668 self.set_verts(verts, closed)
     669 __init__.__doc__ = cbook.dedent(__init__.__doc__) % artist.kwdocd
     670

/usr/lib64/python2.6/site-packages/mpl_toolkits/mplot3d/art3d.pyc in set_verts(self, verts, closed)
     304 def set_verts(self, verts, closed=True):
     305 '''Set 3D vertices.'''
--> 306 self.get_vector(verts)
     307 # 2D verts will be updated at draw time

     308 PolyCollection.set_verts(self, [], closed)

/usr/lib64/python2.6/site-packages/mpl_toolkits/mplot3d/art3d.pyc in get_vector(self, segments3d)
     297 segis.append((si, ei))
     298 si = ei
--> 299 xs, ys, zs = zip(*points)
     300 ones = np.ones(len(xs))
     301 self._vec = np.array([xs, ys, zs, ones])

ValueError: need more than 0 values to unpack
WARNING: Failure executing file: <plot_snr_az.py>

thanks,
David

The shapes of X, Y, and Z must match. After the mesh grid, Z no longer matches X and Y.

Ben Root

(I will be out of contact for at least a week, sorry I won’t be able to help any further till then.)