这是 3D 绘图代码的 MATLAB 版本:编辑:这是当前代码:
plt.figure(2)
fig_b = Axes3D(fig2)
xx2 = np.arange(0, L+h_grid*L, h_grid*L)
yy2 = np.arange(-b, b+h_grid*b, h_grid*b)
X, Y = np.meshgrid(xx2, yy2)
W = np.zeros((41,21), float)
mx = len(xx2)*len(yy2)
X = np.reshape(X, (1, mx))
Y = np.reshape(Y, (1, mx))
W = np.reshape(W, (1, mx))
for j in range(0, mx):
W[0][j] = np.sin(np.pi*X[0][j]/L)
surf = fig_b.plot_surface(X, Y, W, rstride=1, cstride=1, cmap=cm.jet, linewidth=0, antialiased=False) # This is the line number 168
plt.xlabel('x')
plt.ylabel('y')
这是我收到的错误消息:
Traceback (most recent call last):
File "nonhomog.py", line 247, in <module>
main()
File "nonhomog.py", line 245, in main
nonhomog(nu)
File "nonhomog.py", line 168, in nonhomog
surf = fig_b.plot_surface(X, Y, W, rstride=1, cstride=1, cmap=cm.jet, linewidth=0, antialiased=False)
File "/usr/lib/pymodules/python2.6/mpl_toolkits/mplot3d/axes3d.py", line 618, in plot_surface
polyc = art3d.Poly3DCollection(polys, *args, **kwargs)
File "/usr/lib/pymodules/python2.6/mpl_toolkits/mplot3d/art3d.py", line 290, in __init__
PolyCollection.__init__(self, verts, *args, **kwargs)
File "/usr/lib/pymodules/python2.6/matplotlib/collections.py", line 668, in __init__
self.set_verts(verts, closed)
File "/usr/lib/pymodules/python2.6/mpl_toolkits/mplot3d/art3d.py", line 312, in set_verts
self.get_vector(verts)
File "/usr/lib/pymodules/python2.6/mpl_toolkits/mplot3d/art3d.py", line 305, in get_vector
xs, ys, zs = zip(*points)
ValueError: need more than 0 values to unpack