2016-05-11 53 views
0

根据标题,我想知道是否可以暂停matplotlib ArtistAnimation。我知道它是possible to pause when using FuncAnimation,但我不确定该方法可以应用于ArtistAnimation。暂停matplotlib 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) 

回答

0

下面是不是一个完整的解决方案,但也许对一个某种方式。它需要使用IPython。

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

我不确定是否可以让动画在这些调用之后再次开始运行。