-
-
Notifications
You must be signed in to change notification settings - Fork 7.8k
Assign event to later Axes if zorders are tied. #9389
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
Conversation
lib/matplotlib/backend_bases.py
Outdated
@@ -1528,7 +1528,10 @@ def __init__(self, name, canvas, x, y, guiEvent=None): | |||
axes_list = [self.canvas.mouse_grabber] | |||
|
|||
if axes_list: # Use highest zorder. | |||
self.inaxes = max(axes_list, key=lambda x: x.zorder) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we do max(reversed(axes_list), key=lambda x: x.zorder)
instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd rather be explicit about the fact that order in axes_list does matter (at least I wouldn't have thought that the way max
breaks ties is so important by skimming through the code).
lib/matplotlib/backend_bases.py
Outdated
@@ -1528,7 +1528,10 @@ def __init__(self, name, canvas, x, y, guiEvent=None): | |||
axes_list = [self.canvas.mouse_grabber] | |||
|
|||
if axes_list: # Use highest zorder. | |||
self.inaxes = max(axes_list, key=lambda x: x.zorder) | |||
# Use highest zorder; use later axis in case of a tie as they are |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
later Axes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
ee857f5
to
1b675af
Compare
@anntzer This is on a hot-path (created on every mouse move), it may be worth doing a micro-optimization here. |
Apparently I'm not the only one who missed that subtlety (https://github.com/matplotlib/matplotlib/pull/7102/files). Fixing that... |
fixed in a bunch of places and used a slightly overoptimized version :-) |
1b675af
to
0859fd5
Compare
If axes zorders are tied, axes appearing later in figure.axes get drawn above those appearing earlier, so events should be preferably assigned to them. By default, max() returns the *first* maximum in case of ties, so the previous implementation was not satisfactory.
0859fd5
to
7a8a8e7
Compare
Backport PR #9389 on branch v2.1.x
If axes zorders are tied, axes appearing later in figure.axes get
drawn above those appearing earlier, so events should be preferably
assigned to them. By default, max() returns the first maximum in case
of ties, so the previous implementation was not satisfactory.
Closes #9388.
PR Summary
PR Checklist