我一直试图为表面设置动画。到目前为止,所有的动画都是有效的,而且表面也很好地绘制了。然而,我的表面上有一些直线,看起来像是从轴线上看。有没有办法摆脱这个?
# Plot first figure
fig = plt.figure()
ax = fig.gca(projection='3d')
surf = ax.plot_surface(X, Y, Z, rstride=1, cstride=1, cmap=cm.coolwarm,
vmin = 900, vmax = 1430, linewidth=0, antialiased=False)
fig.colorbar(surf, shrink=0.5, aspect=5)
def data(i, X,Y,Z, surf):
#change soln variable for the next frame
ax.clear()
(a,b) = val[i].shape
X = np.arange(0, b)
Y = np.arange(0, a)
X,Y = np.meshgrid(X, Y)
Z = val[i]
surf = ax.plot_surface(X, Y, Z, rstride=1, cstride=1, cmap=cm.coolwarm,
vmin = 900, vmax = 1430, linewidth=0, antialiased=False)
ax.set_xlim(0, 60)
ax.set_ylim(0, 280)
ax.set_zlim(900, 1430)
ax.view_init(azim=10, elev=20)
ax.zaxis.set_major_locator(LinearLocator(10))
ax.zaxis.set_major_formatter(FormatStrFormatter('%.02f'))
return surf
# Add animation
ani = animation.FuncAnimation(fig, data, fargs=(X, Y, Z, surf),
frames=val.size, interval=0.05 , blit=False, repeat=False)
# Full screen window
figManager = plt.get_current_fig_manager()
figManager.window.showMaximized()
plt.show()
答案 0 :(得分:0)
这是一个错误(请参阅此处:https://github.com/matplotlib/matplotlib/issues/750/)。解决方法是通过删除所有对象来手动清除轴。
您需要导入包含曲面的类,以便您可以参考它:from mpl_toolkits.mplot3d.art3d import Poly3DCollection
然后,将ax.clear()
替换为
artists = ax.findobj(match = Poly3DCollection)
for obj in artists:
obj.remove()