File: simple_timer_wx.py

package info (click to toggle)
matplotlib 1.1.1~rc2-1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 66,076 kB
  • sloc: python: 90,600; cpp: 69,891; objc: 5,231; ansic: 1,723; makefile: 171; sh: 7
file content (36 lines) | stat: -rw-r--r-- 779 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
"""
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()