-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
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
Conversation
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() ```
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 add a test so this doesn’t break again?
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 dunno: xdisp, ydisp = ax.transData.transform_point([x, y])
event = MouseEvent('button_press_event', fig.canvas, xdisp, ydisp) doesn't seem that painful.
|
wanna write the test? :) |
I am fine with this going in without a test, not sure it needs to go in for 3.1 though. |
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.
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.
…052-on-v3.1.x Backport PR #14052 on branch v3.1.x (Check axes identity in image.contains.)
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.
Probably a test would be nice, sure.
PR Summary
PR Checklist