Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 8db1a39

Browse files
committed
fixed anim.py to use tk idiom
svn path=/trunk/matplotlib/; revision=5854
1 parent ae9f02e commit 8db1a39

1 file changed

Lines changed: 17 additions & 25 deletions

File tree

examples/animation/anim.py

Lines changed: 17 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,24 @@
11
#!/usr/bin/env python
22
"""
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
164
"""
17-
import time
5+
import matplotlib
6+
matplotlib.use('TkAgg') # do this before importing pylab
187

19-
import pylab as p
8+
import matplotlib.pyplot as plt
9+
fig = plt.figure()
10+
ax = fig.add_subplot(111)
2011

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))
2416

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)
3121

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

Comments
 (0)