Animations in Python with Matplotlib

Veröffentlicht am: 30 November 2019
auf dem Kanal: DMK Data
22,251
179

You can find my blog post about animations with Matplotlib here: http://danielmuellerkomorowska.com/20...

Animations with Matplotlib are easy and anything that can be plotted in a figure can also be animated. We only need the FuncAnimation class which we can import from matplotlib.animation. The only required parameters to create an instance of FuncAnimation are fig, the figure where the animation is supposed to happend, and func, the function that generates each frame in sequence. We can write func ourselves and for most purposes it requires only one parameter, called i. Since an animation requires some sort of change between each frame we need to change what exactly func does and i allows us to do exactly that. An optional parameter of FuncAnimation called frames allows us to specify what exactly is passed to i for each frame. By default it is just a sequence (an itertools.count call to be precise).
In this particular example, frames is a sequence with a step size of 50 and the parameter i tells func which parts of the data to plot for a particular frame. There is one more function called init_func, which is optional but it is important, especially for repeating animations. init_func is called at the beginning of the animation and whenever the animation repeats. So it has to reset the initial state of the figure.
That's it. Let me know if you have questions about animations with Matplotlib.

Example code from this video:
https://gist.github.com/danielmk/c09e...
https://gist.github.com/danielmk/f7d2...

Here is an animation I made with Matplotlib:
   • TSNE of MNIST Test Dataset  

FuncAnimation docs:
https://matplotlib.org/3.1.1/api/_as_...


Auf dieser Seite können Sie das Online-Video Animations in Python with Matplotlib mit der Dauer stunde minuten sekunde in guter Qualität ansehen, das der Benutzer DMK Data 30 November 2019 hochgeladen hat, den Link mit Freunden und Bekannten teilen, dieses Video wurde auf Youtube bereits 22,251 Mal angesehen und es wurde von 179 den Zuschauern gefallen. Viel Spaß beim Betrachtenden Zuschauern gefallen!