I have a python animation script (using matplotlib's funcAnimation), which runs in Spyder but not in Jupyter. I have tried following various suggestions such as adding "%matplotlib inline" and changing the matplotlib backend to "Qt4agg", all without success. I have also tried running several example animations (from Jupyter tutorials), none of which have worked. Sometimes I get an error message and sometimes the plot appears, but does not animate. Incidentally, I have gotten pyplot.plot() to work using "%matplotlib inline".
Does anyone know of a working Jupyter notebook with a SIMPLE inline animation example that uses funcAnimation. Thanks in advance for the help!
[Note: I am on Windows 7]
There is a simple example within this tutorial here: http://louistiao.me/posts/notebooks/embedding-matplotlib-animations-in-jupyter-notebooks/
To summarise the tutorial above, you basically need something like this:
However...
I had a lot of trouble getting that to work. Essentially, the problem was that the above uses (by default)
ffmpeg
and thex264
codec in the background but these were not configured correctly on my machine. The solution was to uninstall them and rebuild them from source with the correct configuration. For more details, see the question I asked about it with a working answer from Andrew Heusser: Animations in ipython (jupyter) notebook - ValueError: I/O operation on closed fileSo, try the
to_html5_video
solution above first, and if it doesn't work then also try the uninstall / rebuild offfmpeg
andx264
.notebook backend
'Inline' means that the plots are shown as png graphics. Those png images cannot be animated. While in principle one could build an animation by successively replacing the png images, this is probably undesired.
A solution is to use the notebook backend, which is fully compatible with
FuncAnimation
as it renders the matplotlib figure itself:jsanimation
From matplotlib 2.1 on, we can create an animation using JavaScript. This is similar to the
ani.to_html5()
solution, except that it does not require any video codecs.Some complete example:
Alternatively, make the jsanimation the default for showing animations,
Then at the end simply state
ani
to obtain the animation.Also see this answer for a complete overview.
Here is the answer that I put together from multiple sources including the official examples. I tested with the latest versions of Jupyter and Python.
imageList
is the only thing that you need to modify. It is an list of images (your input).