Jupyter笔记本,情节出现两次

时间:2018-06-02 14:27:20

标签: python animation matplotlib plot jupyter-notebook

我正在运行一些关于制作动画图的教程中的示例代码。它有效,但不仅仅是一个动画情节,我在我的Jupyter笔记本中得到两个:动画情节和(开始?结束?)动画的快照。为什么会发生这种情况,有什么想法?

import matplotlib.pyplot as plt
from matplotlib import animation, rc
from IPython.display import HTML

fig, ax = plt.subplots()

ax.set_xlim(( 0, 2))
ax.set_ylim((-2, 2))

line, = ax.plot([], [], lw=2)

def init():
    line.set_data([], [])
    return (line,)

def animate(i):
    x = np.linspace(0, 2, 1000)
    y = np.sin(2 * np.pi * (x - 0.01 * i))
    line.set_data(x, y)
    return (line,)


anim = animation.FuncAnimation(fig, animate, init_func=init,
                               frames=100, interval=20, 
                               blit=True)

HTML(anim.to_jshtml())

这就是Jupyter笔记本中输出的样子:

enter image description here

0 个答案:

没有答案