Sophie

Sophie

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

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

.. _old_animation-gtk_timeout:

old_animation example code: gtk_timeout.py
==========================================

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

::

    import gobject
    import numpy as np
    import matplotlib
    matplotlib.use('GTKAgg')
    
    import matplotlib.pyplot as plt
    
    fig = plt.figure()
    ax = fig.add_subplot(111)
    line, = ax.plot(np.random.rand(10))
    ax.set_ylim(0, 1)
    
    def update():
        line.set_ydata(np.random.rand(10))
        fig.canvas.draw_idle()
        return True  # return False to terminate the updates
    
    gobject.timeout_add(100, update)  # you can also use idle_add to update when gtk is idle
    plt.show()
    

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