Skip to content

Backport PR #28271 on branch v3.9.x (Fix draggable legend disappearing when picking while use_blit=True) #28751

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions lib/matplotlib/offsetbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -1486,25 +1486,29 @@
self.canvas.draw()

def on_pick(self, evt):
if self._check_still_parented() and evt.artist == self.ref_artist:
self.mouse_x = evt.mouseevent.x
self.mouse_y = evt.mouseevent.y
self.got_artist = True
if self._use_blit:
if self._check_still_parented():
if evt.artist == self.ref_artist:
self.mouse_x = evt.mouseevent.x
self.mouse_y = evt.mouseevent.y
self.save_offset()
self.got_artist = True
if self.got_artist and self._use_blit:
self.ref_artist.set_animated(True)
self.canvas.draw()
self.background = \
self.canvas.copy_from_bbox(self.ref_artist.figure.bbox)
self.ref_artist.draw(
self.ref_artist.figure._get_renderer())
self.canvas.blit()
self.save_offset()

def on_release(self, event):
if self._check_still_parented() and self.got_artist:
self.finalize_offset()
self.got_artist = False
if self._use_blit:
self.canvas.restore_region(self.background)
self.ref_artist.draw(self.ref_artist.figure._get_renderer())
self.canvas.blit()

Check warning on line 1511 in lib/matplotlib/offsetbox.py

View check run for this annotation

Codecov / codecov/patch

lib/matplotlib/offsetbox.py#L1509-L1511

Added lines #L1509 - L1511 were not covered by tests
self.ref_artist.set_animated(False)

def _check_still_parented(self):
Expand Down
Loading