Sophie

Sophie

distrib > Mandriva > 2010.2 > i586 > media > contrib-backports > by-pkgid > a44f8c7e78ee9c5838c1fb080c9e7630 > files > 1063

python-matplotlib-doc-1.1.1-1mdv2010.1.noarch.rpm

.. _animation-dynamic_image:

animation example code: dynamic_image.py
========================================

[`source code <dynamic_image.py>`_]

::

    #!/usr/bin/env python
    """
    An animated image
    """
    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), cmap=plt.get_cmap('jet'))
    
    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()
    

Keywords: python, matplotlib, pylab, example, codex (see :ref:`how-to-search-examples`)