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

Skip to content

Commit cae28cb

Browse files
committed
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...
1 parent c465993 commit cae28cb

File tree

1 file changed

+2
-4
lines changed

1 file changed

+2
-4
lines changed

lib/matplotlib/widgets.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1811,10 +1811,8 @@ def _press(self, event):
18111811
self.rect.set_visible(self.visible)
18121812
if self.span_stays:
18131813
self.stay_rect.set_visible(False)
1814-
# really force a draw so that the stay rect is not in
1815-
# the blit background
1816-
if self.useblit:
1817-
self.canvas.draw()
1814+
if self.useblit:
1815+
self.canvas.draw()
18181816
xdata, ydata = self._get_data(event)
18191817
if self.direction == 'horizontal':
18201818
self.pressv = xdata

0 commit comments

Comments
 (0)