diff --git a/lib/matplotlib/animation.py b/lib/matplotlib/animation.py index 0f57bc604a36..aabc93e4b8ec 100644 --- a/lib/matplotlib/animation.py +++ b/lib/matplotlib/animation.py @@ -1025,7 +1025,7 @@ def _handle_resize(self, *args): def _end_redraw(self, evt): # Now that the redraw has happened, do the post draw flushing and # blit handling. Then re-enable all of the original events. - self._post_draw(None, self._blit) + self._post_draw(None, False) self.event_source.start() self._fig.canvas.mpl_disconnect(self._resize_id) self._resize_id = self._fig.canvas.mpl_connect('resize_event', diff --git a/lib/matplotlib/backends/backend_qt4agg.py b/lib/matplotlib/backends/backend_qt4agg.py index d36991c84110..e9953e299a6b 100644 --- a/lib/matplotlib/backends/backend_qt4agg.py +++ b/lib/matplotlib/backends/backend_qt4agg.py @@ -77,7 +77,7 @@ def __init__(self, figure): FigureCanvasQTAggBase.__init__(self, figure) FigureCanvasAgg.__init__(self, figure) self._drawRect = None - self.blitbox = None + self.blitbox = [] self.setAttribute(QtCore.Qt.WA_OpaquePaintEvent) diff --git a/lib/matplotlib/backends/backend_qt5agg.py b/lib/matplotlib/backends/backend_qt5agg.py index 5920ab09c7cf..81addae00d27 100644 --- a/lib/matplotlib/backends/backend_qt5agg.py +++ b/lib/matplotlib/backends/backend_qt5agg.py @@ -84,7 +84,7 @@ def paintEvent(self, e): print('FigureCanvasQtAgg.paintEvent: ', self, self.get_width_height()) - if self.blitbox is None: + if len(self.blitbox) == 0: # matplotlib is in rgba byte order. QImage wants to put the bytes # into argb format and is in a 4 byte unsigned int. Little endian # system is LSB first and expects the bytes in reverse order @@ -123,31 +123,34 @@ def paintEvent(self, e): if refcnt != sys.getrefcount(stringBuffer): _decref(stringBuffer) else: - bbox = self.blitbox - l, b, r, t = bbox.extents - w = int(r) - int(l) - h = int(t) - int(b) - t = int(b) + h - reg = self.copy_from_bbox(bbox) - stringBuffer = reg.to_string_argb() - qImage = QtGui.QImage(stringBuffer, w, h, - QtGui.QImage.Format_ARGB32) - # Adjust the stringBuffer reference count to work around a memory - # leak bug in QImage() under PySide on Python 3.x - if QT_API == 'PySide' and six.PY3: - ctypes.c_long.from_address(id(stringBuffer)).value = 1 - - pixmap = QtGui.QPixmap.fromImage(qImage) p = QtGui.QPainter(self) - p.drawPixmap(QtCore.QPoint(l, self.renderer.height-t), pixmap) + + while len(self.blitbox): + bbox = self.blitbox.pop() + l, b, r, t = bbox.extents + w = int(r) - int(l) + h = int(t) - int(b) + t = int(b) + h + reg = self.copy_from_bbox(bbox) + stringBuffer = reg.to_string_argb() + qImage = QtGui.QImage(stringBuffer, w, h, + QtGui.QImage.Format_ARGB32) + # Adjust the stringBuffer reference count to work + # around a memory leak bug in QImage() under PySide on + # Python 3.x + if QT_API == 'PySide' and six.PY3: + ctypes.c_long.from_address(id(stringBuffer)).value = 1 + + pixmap = QtGui.QPixmap.fromImage(qImage) + p.drawPixmap(QtCore.QPoint(l, self.renderer.height-t), pixmap) # draw the zoom rectangle to the QPainter if self._drawRect is not None: p.setPen(QtGui.QPen(QtCore.Qt.black, 1, QtCore.Qt.DotLine)) x, y, w, h = self._drawRect p.drawRect(x, y, w, h) + p.end() - self.blitbox = None def draw(self): """ @@ -190,7 +193,7 @@ def blit(self, bbox=None): if bbox is None and self.figure: bbox = self.figure.bbox - self.blitbox = bbox + self.blitbox.append(bbox) l, b, w, h = bbox.bounds t = b + h self.repaint(l, self.renderer.height-t, w, h) @@ -218,7 +221,7 @@ def __init__(self, figure): print('FigureCanvasQtAgg: ', figure) super(FigureCanvasQTAgg, self).__init__(figure=figure) self._drawRect = None - self.blitbox = None + self.blitbox = [] self.setAttribute(QtCore.Qt.WA_OpaquePaintEvent)