diff --git a/lib/matplotlib/widgets.py b/lib/matplotlib/widgets.py index 37e56a14de59..8336d6353b62 100644 --- a/lib/matplotlib/widgets.py +++ b/lib/matplotlib/widgets.py @@ -1456,8 +1456,21 @@ def update_background(self, event): """Force an update of the background.""" # If you add a call to `ignore` here, you'll want to check edge case: # `release` can call a draw event even when `ignore` is True. - if self.useblit: + if not self.useblit: + return + # Make sure that widget artists don't get accidentally included in the + # background, by re-rendering the background if needed (and then + # re-re-rendering the canvas with the visible widget artists). + needs_redraw = any(artist.get_visible() for artist in self.artists) + with ExitStack() as stack: + if needs_redraw: + for artist in self.artists: + stack.callback(artist.set_visible, artist.get_visible()) + artist.set_visible(False) + self.canvas.draw() self.background = self.canvas.copy_from_bbox(self.ax.bbox) + if needs_redraw: + self.update() def connect_default_events(self): """Connect the major canvas events to methods."""