-
-
Notifications
You must be signed in to change notification settings - Fork 7.7k
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
Improve RectangleSelector Rotation revisited and rebased #26833
base: main
Are you sure you want to change the base?
Conversation
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.
Thank you for opening your first PR into Matplotlib!
If you have not heard from us in a week or so, please leave a new comment below and that should bring it to our attention. Most of our reviewers are volunteers and sometimes things fall through the cracks.
You can also join us on gitter for real-time discussion.
For details on testing, writing docs, and our review process, please see the developer guide
We strive to be a welcoming and open project. Please follow our Code of Conduct.
lib/matplotlib/tests/test_widgets.py
Outdated
|
||
import pytest | ||
|
||
|
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.
Thanks for rebasing this!
If you add this blank line back, the now failing tests should pass.
a9c2945
to
a5c1941
Compare
Tests were failed due to (now yanked) setuptools-scm v8.0.0, restarting tests |
Thanks! I ran into the same issue managing to fetch 8.0.0 in the single hour it was online at condaforge... 😬 |
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.
just the spelling things identified by pre-commit, Haven't looked in detail at the actual code changes yet
We are still having problems with setuptools-scm 8.0.1, though less severe than before, seeming to only really impact Azure 3.9 builds, documented in #26846
lib/matplotlib/widgets.py
Outdated
ymin, ymax = sorted([y0, y1]) | ||
def _clip_to_axes(self, x, y): | ||
""" | ||
Clip x and y values in diplay coordinates to the limits of the current |
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.
Clip x and y values in diplay coordinates to the limits of the current | |
Clip x and y values in display coordinates to the limits of the current |
lib/matplotlib/widgets.py
Outdated
x0 += width - new_wh | ||
width = height = new_wh | ||
|
||
# Transform back into de-rotated display coordiantes |
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.
# Transform back into de-rotated display coordiantes | |
# Transform back into de-rotated display coordinates |
@dhomeier this looks almost good to go, are you planning on coming back to this? |
This currently has an issue with the y limits of the selector 'snapping' to the bottom/x axis - to adapt an example @dhomeier shared with me: import numpy as np
import matplotlib.pyplot as plt
from matplotlib.widgets import RectangleSelector
data = np.random.random((16, 16))
plt.ion()
fig, ax = plt.subplots()
ax.imshow(data)
selector = RectangleSelector(ax, lambda *args: None, interactive=True)
selector.extents = (5, 10, 6, 8)
plt.show(block=True) The following happens: Screencast.from.19-07-24.10.15.14.webmFor some reason the recording doesn't show the cursor but basically I first click on the lower right selection and move it slightly but it snaps to the bottom, then I touch the top right selector and the same thing happens. |
@dhomeier - I've fixed the issue mentioned above in this PR to your branch: dhomeier#13 |
Another issue I ran into when testing this is that the region does not correctly follow the data when resizing the figure: Screencast.from.19-07-24.10.32.46.webm |
Thanks, seems I never properly set that example up with matplotlib on its own, but in astropy/regions#390 those operations are failing with a "negative height" set to the move or resized rectangle, where |
a5c1941
to
5e162fb
Compare
Thanks, that does fix the original |
Ok so the issue in #26833 (comment) is a little tricker as far as I can see - as the selector is defined in display coordinates, it does not follow the data when resizing the figure. We have to somehow cache the position of the selector in data coordinates so that we can change it in |
Actually the issue I mentioned above to do with resizing is exactly what @jklymak mentioned in #21945 (comment) Fundamentally, the issue is that we can't follow a resize since that might change the pixel aspect ratio and so a rotated rectangle would no longer be a rectangle. So maybe what we have here is fine, as it works provided that the user does not resize the window mid-selection. |
@dhomeier - this needs to be rebased to remove the This works nicely for me. I think there is no easy solution to the issue of the region changing in data coordinates when resizing the plot, there's fundamentally no way it will ever not change at all. Once this is rebased, I think it would make sense to proceed with reviewing and hopefully merging this! |
27661fa
to
ced2f13
Compare
That is remove them from all the test jobs, right? |
Yes removing them from the tests. Just to check, did you lose the commit with my bugfix during the rebase? |
Doh, thought I had rebased with that merged already! |
Co-authored-by: David Stansby <[email protected]>
Co-authored-by: David Stansby <[email protected]>
Co-authored-by: David Stansby <[email protected]>
Co-authored-by: David Stansby <[email protected]>
4a25184
to
f2036d5
Compare
f2036d5
to
27c1c11
Compare
During rebase two further issues showed up, addressed in the last two commits:
|
PR summary
This PR rebases the changes from #21945 onto (post-3.8.0)
main
. Since the merge conflicts after almost 2 years became prohibitive, I have applied the original modifications to a fresh PR. Almost all actual code changes are taken from @dstansby's original PR; from its summary:This implementation preserves shapes in display coordinates as discussed in #21945 (comment)
Renamed a property
_geometry_state
in response to #21945 (comment)Last (new) commit to fix
MatplotlibDeprecationWarning: Setting data with a non sequence...
raised by callingself._center_handle.set_data(*self.center)
on a single coordinate array.The workaround does not feel very pretty; might discuss whether
self.center
should instead return a tuple(np.array[xc], np.array[yc])
inmatplotlib/lib/matplotlib/widgets.py
Line 3696 in 2c9919c
but this would in turn break tests like
assert_allclose(tool.center, (50, 65))
.Closes #21937
PR checklist