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

Skip to content

Commit 1417404

Browse files
committed
svn path=/trunk/matplotlib/; revision=2577
1 parent 875212e commit 1417404

3 files changed

Lines changed: 18 additions & 9 deletions

File tree

examples/animation_blit_qt.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,12 @@ def __init__(self):
2929
self.x = nx.arange(0,2*nx.pi,0.01)
3030
self.line, = p.plot(self.x, nx.sin(self.x), animated=True, lw=2)
3131

32-
self.background = self.canvas.copy_from_bbox(self.ax.bbox)
32+
self.background = None
3333

3434
def timerEvent(self, evt):
35+
if self.background is None:
36+
self.background = self.canvas.copy_from_bbox(self.ax.bbox)
37+
3538
# restore the clean slate background
3639
self.canvas.restore_region(self.background)
3740
# update the data
@@ -48,6 +51,9 @@ def timerEvent(self, evt):
4851

4952
else:
5053
self.cnt += 1
54+
55+
p.subplots_adjust(left=0.3, bottom=0.3) # check for flipy bugs
56+
p.grid()
5157

5258
app = BlitQT()
5359
# for profiling

examples/animation_blit_wx.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ def update_line(*args):
4545
# just redraw the axes rectangle
4646

4747
t = time.time()
48-
canvas.blit(ax.bbox)
48+
canvas.blit(ax.bbox)
4949
blit_time += time.time() - t
5050

5151
if update_line.cnt==200:

lib/matplotlib/backends/backend_qtagg.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ def paintEvent( self, e ):
7575
p = qt.QPainter( self )
7676

7777
# only replot data when needed
78-
if type(self.replot) is bool:
78+
if type(self.replot) is bool: # might be a bbox for blitting
7979
if self.replot:
8080
FigureCanvasAgg.draw( self )
8181
stringBuffer = str( self.buffer_rgba(0,0) )
@@ -103,13 +103,16 @@ def paintEvent( self, e ):
103103
p.drawRect( self.rect[0], self.rect[1], self.rect[2], self.rect[3] )
104104

105105
# we are blitting here
106-
else:
106+
else: # TODO: Fix memory leak
107107
bbox = self.replot
108-
self.restore_region(self.copy_from_bbox(bbox))
109-
p.drawPixmap(qt.QPoint(bbox.ll().x().get(),
110-
bbox.ll().y().get()),
111-
self.pixmap)
112-
108+
w, h = int(bbox.width()), int(bbox.height())
109+
l, t = bbox.ll().x().get(), bbox.ur().y().get()
110+
reg = self.copy_from_bbox(bbox)
111+
stringBuffer = reg.to_string()
112+
qImage = qt.QImage(stringBuffer, w, h, 32, None, 0, qt.QImage.IgnoreEndian)
113+
self.pixmap.convertFromImage(qImage, qt.QPixmap.Color)
114+
p.drawPixmap(qt.QPoint(l, self.renderer.height-t), self.pixmap)
115+
113116
p.end()
114117
self.replot = False
115118
self.drawRect = False

0 commit comments

Comments
 (0)