Pausing a matplotlib ArtistAnimation



根据标题,我想知道是否可以暂停matplotlib ArtistAnimation。我知道在使用FuncAnimation时可以暂停,但我不确定该方法是否可以应用于ArtistAnimation。

一个工作的ArtistAnimation没有暂停的例子是

import matplotlib.pyplot as plt
from matplotlib.animation import ArtistAnimation
import numpy as np
fig, ax = plt.subplots()
ax.set(xlim=(0, 2*np.pi), ylim=(-1, 1))
x = np.linspace(0, 2*np.pi, 100)
ims = []  # Blank list that will contain all frames
for frame in range(50):
    line, = ax.plot(x, np.sin(x + 0.1*frame), color='k')
    # Add new element to list with everything that changes between frames
    ims.append([line])
anim = ArtistAnimation(fig, ims, interval=100)

以下不是一个完整的解决方案,但可能有一些方法可以实现。它需要使用IPython。

使用问题中定义的anim,我可以输入anim._stop()来暂停动画。我也可以根据需要使用anim._step()来查看下一帧。

我不确定是否有可能让动画在这些调用后重新开始运行。

最新更新