.. _sphx_glr_gallery_animation_animation_demo.py: ================ pyplot animation ================ Generating an animation by calling `~.pyplot.pause` between plotting commands. The method shown here is only suitable for simple, low-performance use. For more demanding applications, look at the :mod:`animation` module and the examples that use it. Note that calling `time.sleep` instead of `~.pyplot.pause` would *not* work. .. image:: /gallery/animation/images/sphx_glr_animation_demo_001.png :align: center .. code-block:: python import matplotlib.pyplot as plt import numpy as np np.random.seed(19680801) data = np.random.random((50, 50, 50)) fig, ax = plt.subplots() for i in range(len(data)): ax.cla() ax.imshow(data[i]) ax.set_title("frame {}".format(i)) # Note that using time.sleep does *not* work here! plt.pause(0.1) **Total running time of the script:** ( 0 minutes 6.914 seconds) .. only :: html .. container:: sphx-glr-footer .. container:: sphx-glr-download :download:`Download Python source code: animation_demo.py ` .. container:: sphx-glr-download :download:`Download Jupyter notebook: animation_demo.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_