From b29bd158779234ac9941bbefadf5f02d234183ea Mon Sep 17 00:00:00 2001 From: Tim Hoffmann <2836374+timhoffm@users.noreply.github.com> Date: Wed, 2 Apr 2025 20:31:10 +0200 Subject: [PATCH] Backport PR #29842: Don't drag draggables on scroll events --- lib/matplotlib/offsetbox.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/matplotlib/offsetbox.py b/lib/matplotlib/offsetbox.py index 8dd5f4ec23c1..86223e65d6bb 100644 --- a/lib/matplotlib/offsetbox.py +++ b/lib/matplotlib/offsetbox.py @@ -1488,7 +1488,7 @@ def finalize_offset(self): def __init__(self, ref_artist, use_blit=False): self.ref_artist = ref_artist if not ref_artist.pickable(): - ref_artist.set_picker(True) + ref_artist.set_picker(self._picker) self.got_artist = False self._use_blit = use_blit and self.canvas.supports_blit callbacks = self.canvas.callbacks @@ -1502,6 +1502,11 @@ def __init__(self, ref_artist, use_blit=False): ] ] + @staticmethod + def _picker(artist, mouseevent): + # A custom picker to prevent dragging on mouse scroll events + return (artist.contains(mouseevent) and mouseevent.name != "scroll_event"), {} + # A property, not an attribute, to maintain picklability. canvas = property(lambda self: self.ref_artist.get_figure(root=True).canvas) cids = property(lambda self: [