From cae28cba9cc43e2fc6a60d4c579042b521f4b717 Mon Sep 17 00:00:00 2001 From: Antony Lee Date: Wed, 1 Nov 2017 17:50:07 -0700 Subject: [PATCH] Update background in SpanSelector._press whenever useblit=True. Previously, the canvas would only get redrawn when useblit=True only if span_stays is set. This causes e.g. import sys from PyQt5.QtWidgets import * from matplotlib.backends.backend_qt5agg import * from matplotlib.figure import Figure from matplotlib.widgets import SpanSelector class App(QMainWindow): def __init__(self): super().__init__() self.setCentralWidget(QWidget()) layout = QVBoxLayout() self.centralWidget().setLayout(layout) self._fig = Figure() self._fig.subplots() layout.addWidget(FigureCanvas(self._fig)) layout.addWidget(QPushButton("span", clicked=self._span_cb)) def _span_cb(self): self._span = SpanSelector( self._fig.axes[0], print, "horizontal", useblit=True) qapp = QApplication(sys.argv) app = App() app.show() qapp.exec_() to use an incorrect background(?) when clicking and starting a span for the first time. To be honest I'm not sure this is exactly the correct solution, although it does fix the issue... --- lib/matplotlib/widgets.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/lib/matplotlib/widgets.py b/lib/matplotlib/widgets.py index 5ac6986926f6..7ab310a8c941 100644 --- a/lib/matplotlib/widgets.py +++ b/lib/matplotlib/widgets.py @@ -1811,10 +1811,8 @@ def _press(self, event): self.rect.set_visible(self.visible) if self.span_stays: self.stay_rect.set_visible(False) - # really force a draw so that the stay rect is not in - # the blit background - if self.useblit: - self.canvas.draw() + if self.useblit: + self.canvas.draw() xdata, ydata = self._get_data(event) if self.direction == 'horizontal': self.pressv = xdata