老问题,但仍然花了我半天的时间尝试并尝试使用animation.ArtistAnimation()
. 它只是不工作。
我得到的最接近的方法是设置注释,但它一位于绘图上方(不知何故在绘制区域之外)就消失了。
对我有用的animation.FuncAnimation()
是最初的问题中没有给出数据,所以我设置了一些东西。
# generate dummy data
data = []
for i in range(10):
# make these smaller to increase the resolution
dx, dy = 0.05, 0.05
# generate 2 2d grids for the x & y bounds
y, x = np.mgrid[slice(-5, 5 + dy, dy),
slice(-5, 5 + dx, dx)]
z = np.cos((x*x + y*y) - i*2*np.pi/10)
# x and y are bounds, so z should be the value *inside* those bounds.
# Therefore, remove the last value from the z array.
z = z[:-1, :-1]
data.append((x, y, z))
# generate title
titles = ["frame nr {}".format(frame) for frame in range(len(data))]
def func(frame, ax, data, titles):
ax.pcolormesh(*data[frame])
ax.set_title(titles[frame])
return ax
fig = plt.figure()
ax = fig.add_subplot(111)
frames = range(len(data))
ani = animation.FuncAnimation(fig, func, frames, interval=300,
repeat_delay=1000, blit=False,
fargs=(ax, data, titles))