|
1 | 1 | #!/usr/bin/env python |
2 | 2 | """ |
3 | | -A simple example of an animated plot in matplotlib. You can test the |
4 | | -speed of animation of various backends by running the script with the |
5 | | -'-dSomeBackend' flag |
6 | | -
|
7 | | -SC Aug 31 2005 mpl 0.83.2: |
8 | | -Here are some numbers from my system, where FPS is the frames rendered |
9 | | -per second |
10 | | -
|
11 | | - GTK 29 FPS |
12 | | - GTKAgg 18 FPS |
13 | | - GTKCairo 15 FPS |
14 | | - TkAgg 13 FPS |
15 | | - QkAgg 13 FPS |
| 3 | +A simple example of an animated plot in tkagg |
16 | 4 | """ |
17 | | -import time |
| 5 | +import matplotlib |
| 6 | +matplotlib.use('TkAgg') # do this before importing pylab |
18 | 7 |
|
19 | | -import pylab as p |
| 8 | +import matplotlib.pyplot as plt |
| 9 | +fig = plt.figure() |
| 10 | +ax = fig.add_subplot(111) |
20 | 11 |
|
21 | | -# turn interactive mode on for dynamic updates. If you aren't in |
22 | | -# interactive mode, you'll need to use a GUI event handler/timer. |
23 | | -p.ion() |
| 12 | +def animate(): |
| 13 | + tstart = time.time() # for profiling |
| 14 | + x = np.arange(0, 2*np.pi, 0.01) # x-array |
| 15 | + line, = ax.plot(x, np.sin(x)) |
24 | 16 |
|
25 | | -tstart = time.time() # for profiling |
26 | | -x = p.arange(0, 2*p.pi, 0.01) # x-array |
27 | | -line, = p.plot(x, p.sin(x)) |
28 | | -for i in p.arange(1,200): |
29 | | - line.set_ydata(p.sin(x+i/10.0)) # update the data |
30 | | - p.draw() # redraw the canvas |
| 17 | + for i in np.arange(1,200): |
| 18 | + line.set_ydata(np.sin(x+i/10.0)) # update the data |
| 19 | + fig.canvas.draw() # redraw the canvas |
| 20 | + print 'FPS:' , 200/(time.time()-tstart) |
31 | 21 |
|
32 | | -print 'FPS:' , 200/(time.time()-tstart) |
| 22 | +win = fig.canvas.manager.window |
| 23 | +fig.canvas.manager.window.after(100, animate) |
| 24 | +plt.show() |
0 commit comments