【问题标题】:Pausing a matplotlib ArtistAnimation暂停 matplotlib ArtistAnimation
【发布时间】:2016-05-11 23:26:48
【问题描述】:

根据标题,我想知道是否可以暂停 matplotlib ArtistAnimation。我知道它是 possible to pause when using 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)

【问题讨论】:

    标签: python animation matplotlib


    【解决方案1】:

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

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-08-21
      • 1970-01-01
      • 1970-01-01
      • 2013-05-19
      • 2014-06-04
      • 2017-09-09
      相关资源
      最近更新 更多