Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Allow Rectangle and Ellipse selectors to be rotated#19864

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Closed
dstansby wants to merge6 commits intomatplotlib:mainfromdstansby:rotate-selector

Conversation

dstansby
Copy link
Member

@dstansbydstansby commentedApr 4, 2021
edited
Loading

PR Summary

This PR allowsRectangleSelector andEllipseSelector to be rotated about their anchor point. This is enabled by default with the'r' modifier key. Example:

Screen.Recording.2021-04-04.at.21.55.32.mov

PR Checklist

  • Has pytest style unit tests (andpytest passes).
  • IsFlake 8 compliant (runflake8 on changed files to check).
  • New features are documented, with examples if plot related.
  • [ x Documentation is sphinx and numpydoc compliant (the docs shouldbuild without error).
  • Conforms to Matplotlib style conventions (installflake8-docstrings and runflake8 --docstring-convention=all).
  • New features have an entry indoc/users/next_whats_new/ (follow instructions in README.rst there).
  • API changes documented indoc/api/next_api_changes/ (follow instructions in README.rst there).

Copy link
Member

@QuLogicQuLogic left a comment

Choose a reason for hiding this comment

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

There should be tests for resizing after the selector has rotated, which is a thing that could not occur before.

@dstansby
Copy link
MemberAuthor

Thanks for the review - I marked all the minor changes as resolved, and have addressed the other points too.

Copy link
Member

@QuLogicQuLogic left a comment

Choose a reason for hiding this comment

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

Still needs a test of resizing after rotation.

@dstansby
Copy link
MemberAuthor

Still needs a test of resizing after rotation.

Thanks for catching that, it revealed a (now fixed) bug in how I was calculating the resizing. I've also paramatrized the test so it runs for bothRectangle andEllipse selectors.

xc, yc = self.corners
self._corner_handles = ToolHandles(self.ax, xc, yc, marker_props=props,
useblit=self.useblit)

self._edge_order = ['W', 'N', 'E', 'S']
self._edge_order = ['W', 'S', 'E', 'N']
Copy link
Member

Choose a reason for hiding this comment

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

This order hurts my brain ;-) Cardinal directions should be clockwise and start w/ north!. But, I don't think it really matters here....

@QuLogic
Copy link
Member

QuLogic commentedMay 19, 2021
edited
Loading

OK, I tried this out with the rectangle selector example, and it does not work at all in a way I'd expect. One edge barely rotated, while the other turns much more. Sometimes, the rectangle is a completely different aspect ratio. It becomes a parallelogram instead of a rotated rectangle.

@dstansby
Copy link
MemberAuthor

That's because the rectangle is defined in axes coordinates, not figure coordinates. If you doax.set_aspect('equal') it should work as expected. I think it would take quite a bit more work to convertRectangleSelector to be drawn in figure coordinates instead of axes coordinates, but happy to give it a go if people think it's worth blocking this PR on.

@jklymak
Copy link
Member

Yeah I was just getting the point of wondering about that. Is it defined in axes coordinates or data coordinates? If data coordinates, I'm not clear how this is useful.

@dstansby
Copy link
MemberAuthor

I've had a bit of a think about this, and would like to advocate for it to be included as is, with a note (or warning) in the docstring that it doesn't work as expected when the axes aspect ratio != 1. My reasoning is:

  • It doesn't break or modify any existing behavior
  • The motivating use case for this PR was selecting regions in astronomical images. These are almost always displayed with an aspect ratio of 1, where rotating selectors works.

Is it defined in axes coordinates or data coordinates?

It is defined in data coordinates, sorry for the confusion in my earlier comment.

@jklymak
Copy link
Member

@dstansby I understand your use case. OTOH I think its going to be confusing for everyone else when this rotation is not in figure/axes space... Is it hard to put in figure space?

@jklymak
Copy link
Member

@dstansby did you want a definitive answer on this? We could discuss on the call. I guess I'm -0.25 the way the PR is now. Can you implement outside of core?

@dstansby
Copy link
MemberAuthor

Is it hard to put in figure space?

I suspect the answer is technically not hard, but it will take a reasonable amount of development time to disentangle everything to maintain backwards compatibility

Can you implement outside of core?

What do you mean by this? In another package?

I think the deciding question is: Would it be okay to release this as is, and then in the future change (ie. fix) the behavior for aspect!=1 without warning? If not, I'm happy to take a dive into moving the widgets from data to axes coordinates before merging this, but it might take a while.

@jklymak
Copy link
Member

I personally think this should be in figure space, but wouldn't block over it.

@timhoffm
Copy link
Member

We should not inroduce broken rotations. That's rather confusing.

If you cannot make this work for the general case right now, I propose to only enable rotations on equal-aspect Axes. This should be easy to check viaself.ax.get_aspect() == 1.

@jklymakjklymak marked this pull request as draftJune 9, 2021 22:22
@dstansbydstansby marked this pull request as ready for reviewJune 27, 2021 20:02
@dstansby
Copy link
MemberAuthor

If you cannot make this work for the general case right now, I propose to only enable rotations on equal-aspect Axes. This should be easy to check via self.ax.get_aspect() == 1.

Sounds good to me 👍

For a non-equal aspect axes, trying to rotate now does nothing and raises a warning. I've added an extra test to check this works as intended, and updated the docs.

Copy link
Member

@timhoffmtimhoffm left a comment

Choose a reason for hiding this comment

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

Is it possible with reasonable effort to rotate about the center? The tilting over an edge is quite surprising and I don't know any other application doing this.

@QuLogicQuLogic mentioned this pull requestJun 30, 2021
7 tasks
@jklymakjklymak marked this pull request as draftJuly 7, 2021 20:22
@dstansby
Copy link
MemberAuthor

Is it possible with reasonable effort to rotate about the center? The tilting over an edge is quite surprising and I don't know any other application doing this.

I just spent 5 minutes trying to work out if there was an easy way, and couldn't work it out, so I think changing this would take a reasonable amount of effort. This is mainly because aRectangle patch is defined by a corner coordinate and rotation, so it's non trivial (but possible) if one wants to set the rotation angle to be about the center, as a new rotation angle about the corner and corner coordinate has to be calculated for the rectangle at the same time.

@dstansby
Copy link
MemberAuthor

I've rebased this, so should be good for re-review.

@dstansbydstansby marked this pull request as ready for reviewJuly 22, 2021 16:58
@timhoffm
Copy link
Member

I just spent 5 minutes trying to work out if there was an easy way, and couldn't work it out, so I think changing this would take a reasonable amount of effort. This is mainly because aRectangle patch is defined by a corner coordinate and rotation, so it's non trivial (but possible) if one wants to set the rotation angle to be about the center, as a new rotation angle about the corner and corner coordinate has to be calculated for the rectangle at the same time.

Isn't the new location simply:x' = x + d - Md where x is the position vector of the rectangle corner, d is the connection vector from the corner to the center, and M is the rotation matrix?

@dstansby
Copy link
MemberAuthor

Isn't the new location simply:x' = x + d - Md where x is the position vector of the rectangle corner, d is the connection vector from the corner to the center, and M is the rotation matrix?

Possibly? One also needs to work out the new rotation (about the patch corner). If someone wants to take a go at this feel free, I don't currently have the bandwidth to work out the maths or where it needs changing in the code.

@timhoffm
Copy link
Member

timhoffm commentedJul 23, 2021
edited
Loading

One also needs to work out the new rotation (about the patch corner).

I think, you can just do the rotation and then shift the rectangle as proposed.

@ericpre
Copy link
Member

#20839 is an alternative PR to add selector rotation.

@ericpre
Copy link
Member

Done in#20839.

@ericpreericpre closed thisDec 8, 2021
@dstansbydstansby deleted the rotate-selector branchDecember 9, 2021 10:09
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@QuLogicQuLogicQuLogic left review comments

@jklymakjklymakjklymak left review comments

@timhoffmtimhoffmtimhoffm left review comments

Assignees
No one assigned
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

5 participants
@dstansby@QuLogic@jklymak@timhoffm@ericpre

[8]ページ先頭

©2009-2025 Movatter.jp