我想将matplotlib 1.5.1中的3D图添加到现有的2D图(子图)集合中。2D绘图在3D的情况下工作良好,但当我添加3D时,我得到一个错误,即'module‘对象没有属性'plot_surface’。我想保持代码简单,所以我将所有命令应用于plt,而不创建新图形(还有一种使用set_xlabel添加标签的方法),这会使事情变得不明确。前3个图是简单的2D图,最后一个是3D图。
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import axes3d
y1 = u.nodes.concentration
x1 = u.nodes.x
plt.figure(figsize=(20, 10))
plt.subplot(221)
plt.title('Profile')
plt.xlabel('Range')
plt.ylabel('Concentration')
plt.plot(x1, y1, '-b')
# Inhibitor plt
y2 = z.nodes.concentration
x2 = z.nodes.x
plt.subplot(222)
plt.title('Profile')
plt.xlabel('Range')
plt.ylabel('Concentration')
plt.plot(x2, y2, '-r')
# Modulator plt
y3 = v.nodes.concentration
x3 = v.nodes.x
plt.subplot(223)
plt.title('Profile')
plt.xlabel('Range')
plt.ylabel('Concentration')
plt.plot(x3, y3, '-g')
#3D plot
plt.subplot(224, projection='3d')
# Grab data.
xx = u_fft_x_norm
yy = [i*time_period for i in xrange(1, times)]
zz = u_timespace
XX, YY = np.meshgrid(xx, yy)
ZZ = zz
# Plot a basic wireframe.
plt.plot_surface(XX, YY, ZZ, rstride=20, cstride=20)
plt.xlabel('Space')
plt.ylabel('Time')
plt.zlabel('Value')
plt.title('Profile')发布于 2017-06-20 23:04:58
我想错误是不言而喻的。pyplot没有plot_surface命令。也没有迹象表明它应该这样做。看看你找到的所有例子,plot_surface是一个轴的属性。
ax = plt.subplot(224, projection='3d')
ax.plot_surface(X, Y, Z, cmap=cm.coolwarm, linewidth=0, antialiased=False)https://stackoverflow.com/questions/44656502
复制相似问题