Embedding GIF animations in IPython notebook

IPython NBViewer: http://nbviewer.ipython.org/gist/zehsilva/18c28992796d9be99e16
Gist: https://gist.github.com/zehsilva/18c28992796d9be99e16

A couple of days ago I was thinking about the possibility of generating GIF animations using matplotlib and visualizing this animations directly in IPython notebooks. So I did a quick search to find possible solutions, and found one solution to embed videos, and other to convert matplotlib animations to gif, so I combined both solution in a third solution converting the animation to GIF using imagemagick (you will need to have it installed in your computer), enconding the resulting file in a base64 string and embedding this in a img tag. Using IPython.display HTML class this resulting string will be displayed in the notebook (and saved with the notebook).

I will briefly explain the elements of my solution.

Continue reading “Embedding GIF animations in IPython notebook”