There's a simple way to do it with FuncAnimation
:
You must have a function that clears the axis and plot a new contour based on frame number. Don't forget to set blit
as False
.
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()
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…