Fix centre and square state and add rotation for rectangle selector #20839
Conversation
86511fe
to
15fbb09
0f2e907
to
2a68321
@dstansby, since this PR add selector rotation, would you be interested in having a look/reviewing it? The approach used in this PR is slightly different: support for rotation around around the centre is added to the Rectangle patch, which simplifies the changes and also match the behaviour of the ellipse patch. It works with aspect ratio != 1 and the rotation is done around the centre. For the aspect ratio != 1, the default is to use figure coordinates - data coordinates can selected using the |
2a68321
to
0cb15cb
Thanks @timhoffm, I addressed your comments. |
Now the PR title needs updating. |
Sorry, I update the description of this PR but forgot to update the title! |
0cb15cb
to
58bf650
Rebase to fix the merge conflicts. |
58bf650
to
4102b08
4102b08
to
3816a92
I haven't had time to go through everything, but left some comments and questions that are hopefully helpful!
- "center": Make the initial point the center of the shape, | ||
default: "ctrl". | ||
- "center": change the shape around its center, default: "ctrl". | ||
- "data_coordinates": define if data or figure coordinates should be |
It seems weird to have this as part of the state that can change. I think it would be better as a property that is fixed once the selector is created.
Yes, I agree that it doesn't feel very natural. I guess that I have done it that way because of the it follow a similar pattern as rotate/center and it is useful for testing or debugging purpose, but there are not really good reasons! :)
I am happy to have it as a property.
Thanks @dstansby for the review, I shall come back to this PR beginning of Oct to address the comments. |
Moved to draft for now. |
3816a92
to
03648c8
Rebased and addressed @dstansby's review comments. |
The PR has grown to a size that is difficult to review. I did not have time to go through the changes in widgets.py
and test_widgets.py
yet. Part of the problem is that the PR does many things (c.f. the bullet list in the first post).
Review effort scales super-linearly with PR size. So many smaller PRs are better than one large PR. @ericpre is there a chance you can extract some changes into small separate PRs to make review easier?
lib/matplotlib/patches.py
Outdated
@@ -706,7 +706,8 @@ def __str__(self): | |||
return fmt % pars | |||
|
|||
@docstring.dedent_interpd | |||
def __init__(self, xy, width, height, angle=0.0, **kwargs): | |||
def __init__(self, xy, width, height, angle=0.0, |
def __init__(self, xy, width, height, angle=0.0, | |
def __init__(self, xy, width, height, angle=0.0, * |
Let's be defensive and make the new parameter keyword-only.
lib/matplotlib/patches.py
Outdated
Rotation in degrees anti-clockwise about *xy*. | ||
Rotation in degrees anti-clockwise about *xy* if | ||
*rotate_around_center* if False, otherwise rotate around the | ||
center of the rectangle |
center of the rectangle | |
center of the rectangle. |
lib/matplotlib/patches.py
Outdated
Rotation in degrees anti-clockwise about *xy* if | ||
*rotate_around_center* if False, otherwise rotate around the | ||
center of the rectangle | ||
rotate_around_center : bool, default: False |
rotate_around_center : bool, default: False | |
rotation_point : {'xy', 'center'}, default: 'xy' |
Is a better API because it leaves the possibility for other rotation points open.
@@ -1511,6 +1533,8 @@ def __init__(self, xy, width, height, angle=0, **kwargs): | |||
self._width, self._height = width, height | |||
self._angle = angle | |||
self._path = Path.unit_circle() | |||
# Required for EllipseSelector with axes aspect ratio != 1 | |||
self._aspect_ratio_correction = 1.0 |
Please also describe the meaning of the parameter in the comment.
@timhoffm, I fully appreciate that the review effort of this PR are not small and I kept the git history very tidy so that it is easier to understand the logic. Fixing centre and square state correctly was the difficult part and required quite a few iterations on my side (not reflected in this PR) but it made adding support for rotation easy and this is why I finally added in this PR even if this wasn't an original aim of this PR. One part that I could split out of this PR is the changes on the patches - the part that you started reviewing. This part is fairly simple and I suspect the difficult part of this PR can't be split easily or it could end up being unclear or difficult to appreciate the context and motivation. Overall, I am under the impression that that the gain will be marginal if I split in more than 2 PRs. |
@ericpre Thanks for your understanding. I don't have a complete overview of the changes and thus cannot really judge whether splitting is possible. If you can move some aspects out, that would certainly help. I trust your jugement what is reasonable and what is not.
Sorry, I couldn't follow that. One can filter on commits in the "Files changed" tab. Is the proposal something different? |
No, it would be the same but the github functionality will be the much more convenient to use - I wasn't aware of this functionality! |
This PR is affected by a re-writing of our history to remove a large number of accidentally committed files see discourse for details. To recover this PR it will need be rebased onto the new default branch (main). There are several ways to accomplish this, but we recommend (assuming that you call the matplotlib/matplotlib remote git remote update
git checkout main
git merge --ff-only upstream/main
git checkout YOUR_BRANCH
git rebase --onto=main upstream/old_master
# git rebase -i main # if you prefer
git push --force-with-lease # assuming you are tracking your branch If you do not feel comfortable doing this or need any help please reach out to any of the Matplotlib developers. We can either help you with the process or do it for you. Thank you for your contributions to Matplotlib and sorry for the inconvenience. |
… existing shape, part 1, with centering on
… existing shape, part 2, with centering off
1502ef5
to
c7a7a83
PR Summary
data_coordinates
state to define if the square ratio should be calculated in data or figure coordinatesRectangleSelector
andEllipseSelector
taking into account aspect ratio of the axes and using the center of the shape as rotation center.I would expect that this PR conflicts with #19864 and I would be interested to take over #19864 to rebase and fix the outstanding issues.The selector rotation is added in this PR.PR Checklist
pytest
passes).flake8
on changed files to check).flake8-docstrings
and runflake8 --docstring-convention=all
).doc/users/next_whats_new/
(follow instructions in README.rst there).doc/api/next_api_changes/
(follow instructions in README.rst there).The text was updated successfully, but these errors were encountered: