-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Fix centre and square state and add rotation for rectangle selector #20839
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
timhoffm
merged 14 commits into
matplotlib:main
from
ericpre:fix_centre_square_rectangle_selector
Dec 7, 2021
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
f4c01d0
Add method to add default state
ericpre 3a1bde9
Privatize state_modifier_keys
ericpre a6de72c
Take into account aspect ratio in square state
ericpre c748401
Implement rotation selector
ericpre 928e662
Apply inverse transformation to event so that the onmove calculation …
ericpre 9349727
Fix shape rectangle when using rotation and the axes aspect ratio != 1
ericpre 7c47128
Add what's new entry and fix linting
ericpre 8546ca4
Improve documentation, docstring and comments
ericpre 5b9acfe
Make rectangle patch rotation point more generic
ericpre 6e55fc8
Improve documentation
ericpre 5558585
Simplify state selectors and validate `rotation_point` attribute Rect…
ericpre 8ce27d0
Replace the `data_coordinates` state by the `use_data_coordinates` ar…
ericpre c394be8
Improve documentation
ericpre 56710f5
Improve documentation and syntax
ericpre File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
Selector widget state internals | ||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
The *state_modifier_keys* attribute have been privatized and the modifier keys | ||
needs to be set when creating the widget. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
Rectangle patch rotation point | ||
------------------------------ | ||
|
||
The rotation point of the `~matplotlib.patches.Rectangle` can now be set to 'xy', | ||
'center' or a 2-tuple of numbers. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
Selectors improvement: rotation, aspect ratio correction and add/remove state | ||
----------------------------------------------------------------------------- | ||
|
||
The `~matplotlib.widgets.RectangleSelector` and | ||
`~matplotlib.widgets.EllipseSelector` can now be rotated interactively between | ||
-45° and 45°. The range limits are currently dictated by the implementation. | ||
The rotation is enabled or disabled by striking the *r* key | ||
('r' is the default key mapped to 'rotate' in *state_modifier_keys*) or by calling | ||
``selector.add_state('rotate')``. | ||
|
||
The aspect ratio of the axes can now be taken into account when using the | ||
"square" state. This is enabled by specifying ``use_data_coordinates='True'`` when | ||
the selector is initialized. | ||
|
||
In addition to changing selector state interactively using the modifier keys | ||
defined in *state_modifier_keys*, the selector state can now be changed | ||
programmatically using the *add_state* and *remove_state* methods. | ||
|
||
|
||
.. code-block:: python | ||
|
||
import matplotlib.pyplot as plt | ||
from matplotlib.widgets import RectangleSelector | ||
import numpy as np | ||
|
||
values = np.arange(0, 100) | ||
|
||
fig = plt.figure() | ||
ax = fig.add_subplot() | ||
ax.plot(values, values) | ||
|
||
selector = RectangleSelector(ax, print, interactive=True, | ||
drag_from_anywhere=True, | ||
use_data_coordinates=True) | ||
selector.add_state('rotate') # alternatively press 'r' key | ||
# rotate the selector interactively | ||
|
||
selector.remove_state('rotate') # alternatively press 'r' key | ||
|
||
selector.add_state('square') | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.