56 Animating functions and histograms in python using matplotlib
James Franco
Across many fields of science (computational science, data science, etc), matplotlib in Python is used as a static visualisation tool i.e., not animated. But what a lot of people don’t know is that we can also use matplotlib for animations! This is very useful for many applications that aren’t fully explainable via static plots; such as plotting numerical solutions to time-dependent PDEs, or showing how data histograms change over time. The matplotlib framework, while very robust and flexible, can be quite hard to grasp without seeing it used in practice. For example, knowing what the inner workings of a Rectangle or a Line2D object can be very helpful, but won’t necessarily help you in using matplotlib for effective data visualisation. I’d like this .ipynb notebook to be a couple of (simple) examples showing how matplotlib can be used to create animations that can be easily copied and/or extended for other uses. Alongside that, I’ll briefly explain how things work along the way in order to give a high-level overview of what’s going on, but will link the appropriate documentation for more in-depth reading. The notebook will be split up into 3 relevant sections: Using FuncAnimation to animate functions on a set of axes, using FuncAnimation to animate histograms on a set of axes, and finally combining these steps to do both at once, and animate histograms with extra axis information. The notebook can be found at https://github.com/jaf2249/python_animations_using_matplotlib