【问题标题】:How do I get rid of the static graph from matplotlib.animation?如何摆脱 matplotlib.animation 中的静态图?
【发布时间】:2016-11-14 19:35:39
【问题描述】:

这是使用matplotlib 生成动画的代码。当我在 Jupyter notebook 中运行它时,我还会在动画图下方看到另一个静态图。如何删除它?

import numpy as np
import matplotlib.pyplot as plt
from matplotlib.animation import FuncAnimation
from IPython.display import HTML

fig, ax = plt.subplots()

x = np.arange(0, 20, 0.1)
ax.scatter(x, x + np.random.normal(0, 3.0, len(x)))
line, = ax.plot(x, x - 5, 'r-', linewidth=2)

def update(i):
    label = 'timestep {0}'.format(i)
    line.set_ydata(x - 5 + i)
    ax.set_xlabel(label)
    return line, ax

anim = FuncAnimation(fig, update, frames=np.arange(0, 10), interval=200)
HTML(anim.to_html5_video())

【问题讨论】:

  • 您解决了这个问题吗?我遇到了完全相同的问题,但下面的答案似乎没有帮助。

标签: python animation matplotlib jupyter-notebook


【解决方案1】:

我使用了一个名为JSAnimation 的模块(参见this example notebook from the Author)。 要显示动画,您只需调用:

from JSAnimation.IPython_display import display_animation
display_animation(anim)

【讨论】:

    猜你喜欢
    • 2011-01-31
    • 1970-01-01
    • 2013-10-28
    • 1970-01-01
    • 2019-03-10
    • 2010-10-14
    • 2021-08-10
    • 2014-03-01
    • 1970-01-01
    相关资源
    最近更新 更多