Using matplotlib with the
%matplotlib widget magic displays figures as widgets, but there seems to be very little interaction with the animation. It would be nice to have animation controls, but to achieve this I’ve found I have to go around the widget provided and create my own interface, linking up the controls to the animation. Is there a better way to achieve this?
Using matplotlib with the
Since you don’t specifically provide a description of what you are trying to do or a minimal toy code example (always better!), I’ll try to raise some issues and may you can provide more direction in a reply…
I think you are perhaps mixing concepts? Interaction isn’t necessarily animation. And you still have to code in how the interaction works. The ipywidgets
interactive eliminate some of the nitty-gritty of this if your needs can be met by the options that come with those. See here.
(Most of these require an active kernel. This distinction becomes particularly important when discussing animations below.)
If you truly want an animation, that can be done differently and doesn’t need
%matplotlib notebook or
%matplotlib widget or
%matplotlib ipympl, you can use
animation.FuncAnimation() with the ability to make frames from the animation send the animation to
Thanks so much for the pointers. Pretty much what I wanted to achieve was done by:
pyplot.rcParams["animation.html"] = "jshtml"
This seems to make the display of the animation object an interactive style interface. But it is exceedingly slow, so I’m not sure if it is going to be a workable solution. The animation seems to be running by default, even if you aren’t displaying the figure it is attached to. So you, somewhat unexpectedly, have to always call
pause() on it after evaluation.
I guess, ideally, when the animation object is
display()ed in a notebook, then one would get the animation with a way to play/pause/reset it through interaction, much like each figure can be zoomed/panned through interaction.
That isn’t my experience. The example ones that use
plt.rcParams["animation.html"] = "jshtml", do take a while to generate though because they have to generate all the individual frames first. The other methods I describe on that page above mention of the 'Louis Tiao’ don’t generate all the frames and so they play more quickly. However, since they aren’t frame based, you cannot scrub back and forth on demand.
You’ll need to determine which options work best for you. As I point out, once you generate the frames you can make a gif or HTML5-based video you can play elsewhere in a browser, even embedded into Jupyter notebooks that are running actively or ‘static’. The HTML5-based video option including controls.