You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[MNT]: Draggable legend gets stuck on cursor after scroll event #29142
Draggable legend gets stuck to cursor after scrolling while hovering the artist. To 'unstick' it, it is necessary to left click. I believe the expected behavior is to only drag the legend while holding the left mouse button. If that is not the case, please close this issue.
Proposed fix
Sample code:
importmatplotlib.pyplotaspltplt.plot([],[], label='scroll over me, then move the cursor')
plt.legend(draggable=True)
plt.show()
I believe the issue is that the class DraggableBase (at line 1425 of matplotlib/offsetbox.py) uses a 'pick' event to grab the artist, which I believe includes scrolling events. It might be possible to return from a false positive pick by checking that the pick event is a mouse click instead of scrolling at DraggableBase.on_pick. Another alternative is to change the pick event to a button_press event.
I am not sure to be honest. I don't know much about the backends. But the problem described doesn't appear to be the same. In fact I tried implementing my solution inside offsetbox.py and it worked as predicted. Scroll events no longer make legend stick to cursor.
This is the proposed modification (first 3 lines of DraggableBase.on_pick):
defon_pick(self, evt):
# Return if mouseevent is a scroll (this is the modification)ifevt.mouseevent.buttonin ('up','down'):
returnifself._check_still_parented() andevt.artist==self.ref_artist:
self.mouse_x=evt.mouseevent.xself.mouse_y=evt.mouseevent.yself.got_artist=Trueifself._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()
Activity
anntzer commentedon Nov 15, 2024
Perhaps related to #29066 too?
p479h commentedon Nov 16, 2024
I am not sure to be honest. I don't know much about the backends. But the problem described doesn't appear to be the same. In fact I tried implementing my solution inside offsetbox.py and it worked as predicted. Scroll events no longer make legend stick to cursor.
This is the proposed modification (first 3 lines of DraggableBase.on_pick):
anntzer commentedon Nov 21, 2024
Oh, I see. OK, I agree your proposed patch seems reasonable (perhaps rather check
evt.name == "scroll_event", which is more explicit, though).Kaustbh commentedon Dec 3, 2024
Hi can I work on solving this issue?
p479h commentedon Dec 4, 2024
Is the thread author responsible for giving permission? If so, yes.