.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "_examples/matplotlib/plot_main20_animation.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note Click :ref:`here ` to download the full example code .. rst-class:: sphx-glr-example-title .. _sphx_glr__examples_matplotlib_plot_main20_animation.py: 20. Animation ------------------- Create an animation. .. GENERATED FROM PYTHON SOURCE LINES 8-29 .. container:: sphx-glr-animation .. raw:: html
.. code-block:: default :lineno-start: 8 import numpy as np import matplotlib.pyplot as plt import matplotlib.animation as animation # Adapted from # https://matplotlib.org/gallery/animation/basic_example.html def _update_line(num): line.set_data(data[..., :num]) return line, fig, ax = plt.subplots() data = np.random.RandomState(0).rand(2, 25) line, = ax.plot([], [], 'r-') ax.set(xlim=(0, 1), ylim=(0, 1)) ani = animation.FuncAnimation(fig, _update_line, 25, interval=100, blit=True) plt.show() .. rst-class:: sphx-glr-timing **Total running time of the script:** ( 0 minutes 2.538 seconds) .. _sphx_glr_download__examples_matplotlib_plot_main20_animation.py: .. only :: html .. container:: sphx-glr-footer :class: sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_main20_animation.py ` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_main20_animation.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_