擅长:python、mysql、java
<p>使用<code>FuncAnimation</code>有一个简单的方法:
必须具有清除轴并基于帧号绘制新轮廓的函数。别忘了把<code>blit</code>设为<code>False</code>。</p>
<pre><code>import numpy as np
import matplotlib.pyplot as plt
import matplotlib.animation as animation
DATA = np.random.randn(800).reshape(10,10,8)
fig,ax = plt.subplots()
def animate(i):
ax.clear()
ax.contourf(DATA[:,:,i])
ax.set_title('%03d'%(i))
interval = 2#in seconds
ani = animation.FuncAnimation(fig,animate,5,interval=interval*1e+3,blit=False)
plt.show()
</code></pre>