10000 Check axes identity in image.contains. by anntzer · Pull Request #14052 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content

Check axes identity in image.contains. #14052

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
merged 1 commit into from
Apr 29, 2019

Conversation

anntzer
Copy link
Contributor
@anntzer anntzer commented Apr 26, 2019

Otherwise, image.contains(event) will incorrectly return True for a
click in another axes, somewhere else, that happens to be at the same
x/ydata. Try e.g.

from pylab import *
axs = gcf().subplots(2)
im0 = axs[0].imshow([[0, 1], [2, 3]])
im1 = axs[1].imshow([[0, 1], [2, 3]])
gcf().canvas.mpl_connect(
    "button_press_event",
    lambda event: print(im0.contains(event), im1.contains(event)))
show()

Probably a test would be nice, sure.

PR Summary

PR Checklist

  • Has Pytest style unit tests
  • Code is Flake 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

Otherwise, image.contains(event) will incorrectly return True for a
click in *another* axes, somewhere else, that happens to be at the same
x/ydata.  Try e.g.
```
from pylab import *
axs = gcf().subplots(2)
im0 = axs[0].imshow([[0, 1], [2, 3]])
im1 = axs[1].imshow([[0, 1], [2, 3]])
gcf().canvas.mpl_connect(
    "button_press_event",
    lambda event: print(im0.contains(event), im1.contains(event)))
show()
```
@tacaswell tacaswell added this to the v3.1.0 milestone Apr 26, 2019
Copy link
Member
@jklymak jklymak left a comment

Choose a reason for hiding this comment

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

Can we add a test so this doesn’t break again?

@anntzer
Copy link
Contributor Author
anntzer commented Apr 26, 2019

It's a bit of a pain to write these tests (because of the machinery needed to properly generate mouseevents at the right location, see e.g. test_path.py::test_arrow_contains_point); I'd rather write proper machinery (e.g. lifting it from mplcursors' test suite :)) for that instead of duplicating it again and again, but that's not very high in my priority list...
I don't really mind if you want to block the PR on that, but it may sit there for a while :)

@jklymak
Copy link
Member
jklymak commented Apr 26, 2019

I dunno:

xdisp, ydisp = ax.transData.transform_point([x, y])
event = MouseEvent('button_press_event', fig.canvas, xdisp, ydisp)

doesn't seem that painful.

@anntzer
Copy link
Contributor Author
anntzer commented Apr 26, 2019

wanna write the test? :)

@tacaswell
Copy link
Member

I am fine with this going in without a test, not sure it needs to go in for 3.1 though.

Copy link
Contributor
@dopplershift dopplershift left a comment

Choose a reason for hiding this comment

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

Since this is a blocker for 3.1, I don't want to hold it up for tests. It would be nice, sure, and I'd be happy to review and merge a separate PR for it, but let's just get this in.

@dopplershift dopplershift merged commit 73c0ed6 into matplotlib:master Apr 29, 2019
meeseeksmachine pushed a commit to meeseeksmachine/matplotlib that referenced this pull request Apr 29, 2019
@anntzer anntzer deleted the image-contains branch April 29, 2019 19:14
dstansby added a commit that referenced this pull request Apr 29, 2019
…052-on-v3.1.x

Backport PR #14052 on branch v3.1.x (Check axes identity in image.contains.)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants
0