.. _sphx_glr_gallery_animation_dynamic_image.py: ================= An animated image ================= This example demonstrates how to animate an image. .. image:: /gallery/animation/images/sphx_glr_dynamic_image_001.png :align: center .. code-block:: python import numpy as np import matplotlib.pyplot as plt import matplotlib.animation as animation fig = plt.figure() def f(x, y): return np.sin(x) + np.cos(y) x = np.linspace(0, 2 * np.pi, 120) y = np.linspace(0, 2 * np.pi, 100).reshape(-1, 1) im = plt.imshow(f(x, y), animated=True) def updatefig(*args): global x, y x += np.pi / 15. y += np.pi / 20. im.set_array(f(x, y)) return im, ani = animation.FuncAnimation(fig, updatefig, interval=50, blit=True) plt.show() **Total running time of the script:** ( 0 minutes 0.037 seconds) .. only :: html .. container:: sphx-glr-footer .. container:: sphx-glr-download :download:`Download Python source code: dynamic_image.py ` .. container:: sphx-glr-download :download:`Download Jupyter notebook: dynamic_image.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_