The issue I;'m having is that displaying the JavaScript animation in a jupyter notebook shows the plot as well:
Code for the example:
fig = plt.figure()
ax = plt.axes(xlim=(0, 2), 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=200, interval=20, blit=True)
HTML(anim.to_jshtml())
Notice that this results in two plots instead of just the animation.
On a different note I have tried running it with:
HTML(anim.to_html5_video())
but that gives me one of these errors:
---------------------------------------------------------------------------
KeyError Traceback (most recent call last)
~\AppData\Local\Continuum\miniconda3\lib\site-packages\matplotlib\animation.py in __getitem__(self, name)
169 try:
--> 170 return self.avail[name]
171 except KeyError:
KeyError: 'ffmpeg'
During handling of the above exception, another exception occurred:
RuntimeError Traceback (most recent call last)
<ipython-input-30-b5253c68f7fe> in <module>()
20 frames=200, interval=20, blit=True)
21
---> 22 HTML(anim.to_html5_video())
~\AppData\Local\Continuum\miniconda3\lib\site-packages\matplotlib\animation.py in to_html5_video(self, embed_limit)
1347 # We create a writer manually so that we can get the
1348 # appropriate size for the tag
-> 1349 Writer = writers[rcParams['animation.writer']]
1350 writer = Writer(codec='h264',
1351 bitrate=rcParams['animation.bitrate'],
~\AppData\Local\Continuum\miniconda3\lib\site-packages\matplotlib\animation.py in __getitem__(self, name)
171 except KeyError:
172 raise RuntimeError(
--> 173 'Requested MovieWriter ({}) not available'.format(name))
174
175
RuntimeError: Requested MovieWriter (ffmpeg) not available
and installing ffmpeg is not helping.