我必须设置blit = true,因为绘制速度更快。但是在动画(重复= false)之后,如果我在图中使用缩放,则该图将消失。我需要保留最后一帧,以便可以放大最后一个数字。
谢谢!
答案 0 :(得分:0)
一种解决方法是使用最后一帧初始化动画。明显的缺点是您必须预先计算最后一帧。改编this example将
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.animation as animation
fig, ax = plt.subplots()
x = np.arange(0, 2*np.pi, 0.01)
line, = ax.plot(x, np.sin(x))
cnt = 50 # Define so we know what the last frame will be.
def init():
# Note the function is the same as `animate` with `i` set to the last value
line.set_ydata(np.sin(x + cnt / 100))
return line,
def animate(i):
line.set_ydata(np.sin(x + i / 100)) # update the data.
return line,
ani = animation.FuncAnimation(
fig, animate, init_func=init, interval=2, blit=True, save_count=cnt)
ani.save("mwe.mov")
fig.savefig("mwe.png")