Sophie

Sophie

distrib > Fedora > 18 > i386 > by-pkgid > bf21b4394f4d7fa09e3626145d3315e0 > files > 279

python-matplotlib-doc-1.2.0-14.fc18.i686.rpm

.. _old_animation-simple_timer_wx:

old_animation example code: simple_timer_wx.py
==============================================

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

::

    from __future__ import print_function
    """
    A simple example of an animated plot using a wx backend
    """
    import time
    import numpy as np
    import matplotlib
    matplotlib.use('WXAgg') # do this before importing pylab
    
    import matplotlib.pyplot as plt
    
    fig = plt.figure()
    
    ax = fig.add_subplot(111)
    t = np.arange(0, 2*np.pi, 0.1)
    line, = ax.plot(t, np.sin(t))
    dt = 0.05
    
    
    def update_line(event):
        if update_line.i==200:
            return False
        print('update', update_line.i)
        line.set_ydata(np.sin(t+update_line.i/10.))
        fig.canvas.draw()                 # redraw the canvas
        update_line.i += 1
    update_line.i = 0
    
    import wx
    id = wx.NewId()
    actor = fig.canvas.manager.frame
    timer = wx.Timer(actor, id=id)
    timer.Start(100)
    wx.EVT_TIMER(actor, id, update_line)
    #actor.Bind(wx.EVT_TIMER, update_line, id=id)
    
    plt.show()
    

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