diff --git a/lib/matplotlib/backend_bases.py b/lib/matplotlib/backend_bases.py index 33bb7294d5e5..b23013cdd9b5 100644 --- a/lib/matplotlib/backend_bases.py +++ b/lib/matplotlib/backend_bases.py @@ -2763,6 +2763,10 @@ def draw_rubberband(self, event, x0, y0, x1, y1): """Draw a rectangle rubberband to indicate zoom limits""" pass + def remove_rubberband(self): + """Remove the rubberband""" + pass + def forward(self, *args): """Move forward in the view lim stack""" self._views.forward() @@ -3036,6 +3040,8 @@ def release_zoom(self, event): self.canvas.mpl_disconnect(zoom_id) self._ids_zoom = [] + self.remove_rubberband() + if not self._xypress: return diff --git a/lib/matplotlib/backends/backend_qt4agg.py b/lib/matplotlib/backends/backend_qt4agg.py index b6830573c983..fc7a1f58ee1a 100644 --- a/lib/matplotlib/backends/backend_qt4agg.py +++ b/lib/matplotlib/backends/backend_qt4agg.py @@ -54,8 +54,8 @@ def new_figure_manager_given_figure(num, figure): return FigureManagerQT(canvas, num) -class FigureCanvasQTAgg(FigureCanvasQTAggBase, - FigureCanvasQT, FigureCanvasAgg): +class FigureCanvasQTAgg(FigureCanvasQT, FigureCanvasQTAggBase, + FigureCanvasAgg): """ The canvas the figure renders into. Calls the draw and print fig methods, creates the renderers, etc... @@ -69,6 +69,7 @@ def __init__(self, figure): if DEBUG: print('FigureCanvasQtAgg: ', figure) FigureCanvasQT.__init__(self, figure) + FigureCanvasQTAggBase.__init__(self, figure) FigureCanvasAgg.__init__(self, figure) self._drawRect = None self.blitbox = None diff --git a/lib/matplotlib/backends/backend_qt5.py b/lib/matplotlib/backends/backend_qt5.py index b92f545772bf..82da2c1cfa69 100644 --- a/lib/matplotlib/backends/backend_qt5.py +++ b/lib/matplotlib/backends/backend_qt5.py @@ -415,9 +415,6 @@ def stop_event_loop(self): stop_event_loop.__doc__ = FigureCanvasBase.stop_event_loop_default.__doc__ - def draw_idle(self): - self.update() - class MainWindow(QtWidgets.QMainWindow): closing = QtCore.Signal() @@ -685,6 +682,9 @@ def draw_rubberband(self, event, x0, y0, x1, y1): rect = [int(val)for val in (min(x0, x1), min(y0, y1), w, h)] self.canvas.drawRectangle(rect) + def remove_rubberband(self): + self.canvas.drawRectangle(None) + def configure_subplots(self): image = os.path.join(matplotlib.rcParams['datapath'], 'images', 'matplotlib.png') diff --git a/lib/matplotlib/backends/backend_qt5agg.py b/lib/matplotlib/backends/backend_qt5agg.py index 8d6638ad4e5c..e7072e14d162 100644 --- a/lib/matplotlib/backends/backend_qt5agg.py +++ b/lib/matplotlib/backends/backend_qt5agg.py @@ -58,12 +58,16 @@ class FigureCanvasQTAggBase(object): Public attribute - figure - A Figure instance - """ + figure - A Figure instance + """ + + def __init__(self, figure): + super(FigureCanvasQTAggBase, self).__init__(figure=figure) + self._agg_redraw_flag = True def drawRectangle(self, rect): self._drawRect = rect - self.draw_idle() + self.update() def paintEvent(self, e): """ @@ -71,7 +75,9 @@ def paintEvent(self, e): In Qt, all drawing should be done inside of here when a widget is shown onscreen. """ - FigureCanvasAgg.draw(self) + if self._agg_redraw_flag: + self._agg_redraw_flag = False + FigureCanvasAgg.draw(self) # FigureCanvasQT.paintEvent(self, e) if DEBUG: @@ -134,9 +140,14 @@ def paintEvent(self, e): pixmap = QtGui.QPixmap.fromImage(qImage) p = QtGui.QPainter(self) 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 - self._drawRect = None def draw(self): """ @@ -147,6 +158,11 @@ def draw(self): # causes problems with code that uses the result of the # draw() to update plot elements. FigureCanvasAgg.draw(self) + self._agg_redraw_flag = False + self.update() + + def draw_idle(self): + self._agg_redraw_flag = True self.update() def blit(self, bbox=None): @@ -161,6 +177,7 @@ def blit(self, bbox=None): self.blitbox = bbox l, b, w, h = bbox.bounds t = b + h + self._agg_redraw_flag = False # don't repaint the agg buffer in blit() self.repaint(l, self.renderer.height-t, w, h) def print_figure(self, *args, **kwargs): @@ -168,8 +185,8 @@ def print_figure(self, *args, **kwargs): self.draw() -class FigureCanvasQTAgg(FigureCanvasQTAggBase, - FigureCanvasQT, FigureCanvasAgg): +class FigureCanvasQTAgg(FigureCanvasQT, FigureCanvasQTAggBase, + FigureCanvasAgg): """ The canvas the figure renders into. Calls the draw and print fig methods, creates the renderers, etc. @@ -184,8 +201,7 @@ class FigureCanvasQTAgg(FigureCanvasQTAggBase, def __init__(self, figure): if DEBUG: print('FigureCanvasQtAgg: ', figure) - FigureCanvasQT.__init__(self, figure) - FigureCanvasAgg.__init__(self, figure) + super(FigureCanvasQTAgg, self).__init__(figure=figure) self._drawRect = None self.blitbox = None self.setAttribute(QtCore.Qt.WA_OpaquePaintEvent)