Menu

[r3364]: / trunk / matplotlib / examples / animation_blit_qt.py  Maximize  Restore  History

Download this file

65 lines (49 with data), 1.8 kB

 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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# For detailed comments on animation and the techniqes used here, see
# the wiki entry http://www.scipy.org/Cookbook/Matplotlib/Animations
import os, sys
import matplotlib
matplotlib.use('QtAgg') # qt3 example
from qt import *
# Note: color-intensive applications may require a different color allocation
# strategy.
QApplication.setColorSpec(QApplication.NormalColor)
TRUE = 1
FALSE = 0
ITERS = 1000
import pylab as p
import matplotlib.numerix as nx
import time
class BlitQT(QObject):
def __init__(self):
QObject.__init__(self, None, "app")
self.ax = p.subplot(111)
self.canvas = self.ax.figure.canvas
self.cnt = 0
# create the initial line
self.x = nx.arange(0,2*nx.pi,0.01)
self.line, = p.plot(self.x, nx.sin(self.x), animated=True, lw=2)
self.background = None
def timerEvent(self, evt):
if self.background is None:
self.background = self.canvas.copy_from_bbox(self.ax.bbox)
# restore the clean slate background
self.canvas.restore_region(self.background)
# update the data
self.line.set_ydata(nx.sin(self.x+self.cnt/10.0))
# just draw the animated artist
self.ax.draw_artist(self.line)
# just redraw the axes rectangle
self.canvas.blit(self.ax.bbox)
if self.cnt==ITERS:
# print the timing info and quit
print 'FPS:' , ITERS/(time.time()-self.tstart)
sys.exit()
else:
self.cnt += 1
p.subplots_adjust(left=0.3, bottom=0.3) # check for flipy bugs
p.grid() # to ensure proper background restore
app = BlitQT()
# for profiling
app.tstart = time.time()
app.startTimer(0)
p.show()
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.