Skip to content

Commit 135692c

Browse files
committed
added simple gtk animation example
svn path=/trunk/matplotlib/; revision=5857
1 parent db72044 commit 135692c

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
"""
2+
A simple example of an animated plot using a gtk backends
3+
"""
4+
import time
5+
import numpy as np
6+
import matplotlib
7+
matplotlib.use('GTKAgg') # do this before importing pylab
8+
9+
import matplotlib.pyplot as plt
10+
11+
fig = plt.figure()
12+
13+
ax = fig.add_subplot(111)
14+
15+
def animate():
16+
tstart = time.time() # for profiling
17+
x = np.arange(0, 2*np.pi, 0.01) # x-array
18+
line, = ax.plot(x, np.sin(x))
19+
20+
for i in np.arange(1,200):
21+
line.set_ydata(np.sin(x+i/10.0)) # update the data
22+
fig.canvas.draw() # redraw the canvas
23+
print 'FPS:' , 200/(time.time()-tstart)
24+
raise SystemExit
25+
26+
import gobject
27+
print 'adding idle'
28+
gobject.idle_add(animate)
29+
print 'showing'
30+
plt.show()

0 commit comments

Comments
 (0)