Skip to content

Assign event to later Axes if zorders are tied. - #9389

Merged
dstansby merged 1 commit into
matplotlib:masterfrom
anntzer:overlayed-axes-events
Oct 30, 2017
Merged

dstansby merged 1 commit into
matplotlib:masterfrom
anntzer:overlayed-axes-events

Conversation

@anntzer

@anntzer anntzer commented Oct 13, 2017

Copy link
Copy Markdown
Contributor

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

  • Has Pytest style unit tests
  • Code is PEP 8 compliant
  • New features are documented, with examples if plot related
  • Documentation is sphinx and numpydoc compliant
  • Added an entry to doc/users/next_whats_new/ if major new feature (follow instructions in README.rst there)
  • Documented in doc/api/api_changes.rst if API changed in a backward-incompatible way

@anntzer anntzer added the Release critical For bugs that make the library unusable (segfaults, incorrect plots, etc) and major regressions. label Oct 13, 2017
@anntzer anntzer added this to the 2.1.1 (next bug fix release) milestone Oct 13, 2017
axes_list = [self.canvas.mouse_grabber]

if axes_list: # Use highest zorder.
self.inaxes = max(axes_list, key=lambda x: x.zorder)

Copy link
Copy Markdown
Member

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?

Copy link
Copy Markdown
Contributor Author

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).

Comment thread lib/matplotlib/backend_bases.py Outdated

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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

later Axes

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

@anntzer
anntzer force-pushed the overlayed-axes-events branch from ee857f5 to 1b675af Compare October 13, 2017 19:57
@tacaswell

Copy link
Copy Markdown
Member

@anntzer This is on a hot-path (created on every mouse move), it may be worth doing a micro-optimization here.

@anntzer

anntzer commented Oct 15, 2017

Copy link
Copy Markdown
Contributor Author

Apparently I'm not the only one who missed that subtlety (https://github.com/matplotlib/matplotlib/pull/7102/files). Fixing that...

@anntzer

anntzer commented Oct 15, 2017

Copy link
Copy Markdown
Contributor Author

fixed in a bunch of places and used a slightly overoptimized version :-)

@anntzer
anntzer force-pushed the overlayed-axes-events branch from 1b675af to 0859fd5 Compare October 15, 2017 04:06
@tacaswell tacaswell closed this Oct 21, 2017
@tacaswell tacaswell reopened this Oct 21, 2017
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.
@anntzer
anntzer force-pushed the overlayed-axes-events branch from 0859fd5 to 7a8a8e7 Compare October 21, 2017 19:09
@dstansby
dstansby merged commit 5c9f49a into matplotlib:master Oct 30, 2017
@anntzer
anntzer deleted the overlayed-axes-events branch October 30, 2017 19:38
QuLogic added a commit that referenced this pull request Oct 31, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Release critical For bugs that make the library unusable (segfaults, incorrect plots, etc) and major regressions.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Mouse events have incorrect inaxes/data properties when axes overlap (matplotlib 2.1.0)

4 participants