8000 Improve documentation · matplotlib/matplotlib@6434911 · GitHub
[go: up one dir, main page]

Skip to content

Commit 6434911

Browse files
committed
Improve documentation
1 parent 68d00dd commit 6434911

File tree

5 files changed

+22
-11
lines changed

5 files changed

+22
-11
lines changed
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
Selector widget state internals
22
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3-
*state_modifier_keys* now have to be defined when creating a selector widget.
4-
The *state_modifier_keys* attribute is deprecated.
3+
*state_modifier_keys* are immutable now. They can be set when creating the
4+
widget, but cannot be changed afterwards anymore.
Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,16 @@
1-
Selectors improvement
2-
---------------------
1+
Rotating selectors and aspect ratio correction
2+
----------------------------------------------
33

44
The `~matplotlib.widgets.RectangleSelector` and
5-
`~matplotlib.widgets.EllipseSelector` can now be rotated interactively. The rotation is
6-
enabled and disabled by pressing the 'r' key.
7-
The "square" shape can be defined in data or display coordinate system as defined
8-
by the *data_coordinates* modifier.
5+
`~matplotlib.widgets.EllipseSelector` can now be rotated interactively.
6+
7+
The rotation is enabled when *rotate* is added to
8+
:py:attr:`~matplotlib.widgets._SelectorWidget.state`, which can be done using
9+
:py:meth:`~matplotlib.widgets._SelectorWidget.add_state` or by striking
10+
the *state_modifier_keys* for *rotate* (default *r*).
11+
12+
The aspect ratio of the axes can now be taken into account when using the
13+
"square" state. When *data_coordinates* is added to
14+
:py:attr:`~matplotlib.widgets._SelectorWidget.state`, which can be done using
15+
:py:meth:`~matplotlib.widgets._SelectorWidget.add_state` or by striking
16+
the *state_modifier_keys* for *data_coordinates* (default *d*).

lib/matplotlib/patches.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -721,7 +721,7 @@ def __init__(self, xy, width, height, angle=0.0, *,
721721
Rotation in degrees anti-clockwise about the rotation point.
722722
rotation_point : {'xy', 'center', (number, number)}, default: 'xy'
723723
If ``'xy'``, rotate around the anchor point. If ``'center'`` rotate
724-
around the center. If 2-tuple of number, rotate around these
724+
around the center. If 2-tuple of number, rotate around this
725725
coordinate.
726726
727727
Other Parameters
@@ -740,7 +740,8 @@ def __init__(self, xy, width, height, angle=0.0, *,
740740
# The patch is defined in data coordinates and when changing the
741741
# selector with square modifier and not in data coordinates, we need
742742
# to correct for the aspect ratio difference between the data and
743-
# display coordinate systems.
743+
# display coordinate systems. Its value is typically provide by
744+
# Axes._get_aspect_ratio()
744745
self._aspect_ratio_correction = 1.0
745746
self._convert_units() # Validate the inputs.
746747

lib/matplotlib/tests/test_widgets.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,6 @@ def onselect(epress, erelease):
440440
tool.rotation = 45
441441
assert tool.rotation == 45
442442
# Corners should move
443-
# The third corner is at (100, 145)
444443
assert_allclose(tool.corners,
445444
np.array([[118.53, 139.75, 111.46, 90.25],
446445
[95.25, 116.46, 144.75, 123.54]]), atol=0.01)

lib/matplotlib/widgets.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3048,10 +3048,13 @@ def _onmove(self, event):
30483048

30493049
dx = event.xdata - eventpress.xdata
30503050
dy = event.ydata - eventpress.ydata
3051+
# refmax is used when moving the corner handle with the square state
3052+
# and is the maximum between refx and refy
30513053
refmax = None
30523054
if 'data_coordinates' in state:
30533055
refx, refy = dx, dy
30543056
else:
3057+
# Add 1e-6 to avoid divided by zero error
30553058
refx = event.xdata / (eventpress.xdata + 1e-6)
30563059
refy = event.ydata / (eventpress.ydata + 1e-6)
30573060

0 commit comments

Comments
 (0)
0