Sophie

Sophie

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

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

.. _animation-random_data:

animation example code: random_data.py
======================================

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

::

    import numpy as np
    import matplotlib.pyplot as plt
    import matplotlib.animation as animation
    
    fig = plt.figure()
    ax = fig.add_subplot(111)
    line, = ax.plot(np.random.rand(10))
    ax.set_ylim(0, 1)
    
    def update(data):
        line.set_ydata(data)
        return line,
    
    def data_gen():
        while True: yield np.random.rand(10)
    
    ani = animation.FuncAnimation(fig, update, data_gen, interval=100)
    plt.show()
    

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