Python:如何使用matplotlib.animation?
我试图使用matplotlib.animation来制作曲面动画,但我无法真正理解文档,无论如何,这是我的代码:Python:如何使用matplotlib.animation?,python,matplotlib,Python,Matplotlib,我试图使用matplotlib.animation来制作曲面动画,但我无法真正理解文档,无论如何,这是我的代码: import numpy as np import matplotlib.pyplot as plt import mpl_toolkits.mplot3d.axes3d as p3 import matplotlib.animation as animation from matplotlib import cm dimension=1.5 X=np.arange(-di
import numpy as np
import matplotlib.pyplot as plt
import mpl_toolkits.mplot3d.axes3d as p3
import matplotlib.animation as animation
from matplotlib import cm
dimension=1.5
X=np.arange(-dimension,dimension,0.01)
Y=np.arange(-dimension,dimension,0.01)
X, Y = np.meshgrid(X,Y)
def drum(t): #only a test, will be edited in future
Z=(X**2+Y**2)*np.cos(t*0.01)
return Z
def update_drum(t):
ax.clear()
ax.plot_surface(X, Y, drum(t), cmap=cm.coolwarm,
linewidth=0, antialiased=False)
plt.show
# Attaching 3D axis to the figure
fig = plt.figure()
ax = p3.Axes3D(fig)
# Setting the axes properties
ax.set_xlim3d([-dimension-0.5,0.5+dimension])
ax.set_xlabel('X')
ax.set_ylim3d([-dimension-0.5,0.5+dimension])
ax.set_ylabel('Y')
ax.set_zlim3d([-3.0, 3.0])
ax.set_zlabel('Z')
ax.set_title('Resonant modes')
# Creating the Animation object
ani = animation.FuncAnimation(fig, update_drum, 25,
interval=50, blit=True)
结果我得到了这个错误:
axes = set(a.axes for a in artists)
"TypeError: 'Axes3D' object is not iterable".
下面是我的问题:
- 如何修改FuncAnimation(更新)调用的函数
- 如何解决“Axes3D”对象不可编辑”错误
谢谢尝试删除blit争论
If blit=True, func and init_func should return an iterable of drawables to clear.
您返回的是一个Axes3D,而不是一个可拖动的iterable