2016-05-11 79 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()來查看下一幀。

我不確定是否可以讓動畫在這些調用之後再次開始運行。