Embedding Matplotlib Animations in Jupyter as Interactive JavaScript Widgets
A while back I wrote a post on Embedding Matplotlib Animations in Jupyter Noteboks, which became surprisingly popular. It outlined how to render Matplotlib animations in the Jupyter Notebook, by encoding it as a HTML5 video using the to_html5_video
method introduced in the release of Matplotlib 1.5.
Three years have gone by since then, and much has changed in the world of open-source scientific Python. Matplotlib 2.1 was released towards the end of last year, and was the first release with major new features since 1.5. Among many significant enhancements, the release included the merge of Jake Vanderplas' JSAnimation package, a tool for rendering Matplotlib animations as interactive JavaScript widgets.
With this awesome addition, encapsulated in the new to_jshtml
method,
we are now able to embed an interactive JavaScript widget for playback of Matplotlib animations directly inside a Jupyter Notebook.
In this post, we demonstrate how to use this method on the same example animation from my previous post, which was originally derived from an even earlier post by Jake VanderPlas.