8000 Improve documentation and syntax · matplotlib/matplotlib@56710f5 · GitHub
[go: up one dir, main page]

Skip to content

Commit 56710f5

Browse files
committed
Improve documentation and syntax
1 parent c394be8 commit 56710f5

File tree

4 files changed

+24
-12
lines changed

4 files changed

+24
-12
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* are immutable now. They can be set when creating the
4-
widget, but cannot be changed afterwards anymore.
3+
The *state_modifier_keys* attribute have been privatized and the modifier keys
4+
needs to be set when creating the widget.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Rectangle patch rotation point
2+
------------------------------
3+
4+
The rotation point of the `~matplotlib.patches.Rectangle` can now be set to 'xy',
5+
'center' or a 2-tuple of numbers.

doc/users/next_whats_new/selector_improvement.rst

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@ Selectors improvement: rotation, aspect ratio correction and add/remove state
22
-----------------------------------------------------------------------------
33

44
The `~matplotlib.widgets.RectangleSelector` and
5-
`~matplotlib.widgets.EllipseSelector` can now be rotated interactively.
6-
The rotation is enabled or disable by striking the *r* key
5+
`~matplotlib.widgets.EllipseSelector` can now be rotated interactively between
6+
-45° and 45°. The range limits are currently dictated by the implementation.
7+
The rotation is enabled or disabled by striking the *r* key
78
('r' is the default key mapped to 'rotate' in *state_modifier_keys*) or by calling
89
``selector.add_state('rotate')``.
910

lib/matplotlib/widgets.py

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1835,7 +1835,7 @@ def __init__(self, ax, onselect, useblit=False, button=None,
18351835
eventpress = _api.deprecate_privatize_attribute("3.5")
18361836
eventrelease = _api.deprecate_privatize_attribute("3.5")
18371837
state = _api.deprecate_privatize_attribute("3.5")
1838-
state_modifier_keys = _api.deprecate_privatize_attribute("3.5")
1838+
state_modifier_keys = _api.deprecate_privatize_attribute("3.6")
18391839

18401840
def set_active(self, active):
18411841
super().set_active(active)
@@ -2803,7 +2803,8 @@ def onselect(eclick: MouseEvent, erelease: MouseEvent)
28032803
- "clear": Clear the current shape, default: "escape".
28042804
- "square": Make the shape square, default: "shift".
28052805
- "center": change the shape around its center, default: "ctrl".
2806-
- "rotate": Rotate the shape around its center, default: "r".
2806+
- "rotate": Rotate the shape around its center between -45° and 45°,
2807+
default: "r".
28072808
28082809
"square" and "center" can be combined. The square shape can be defined
28092810
in data or figure coordinates as determined by the
@@ -3061,7 +3062,8 @@ def _onmove(self, event):
30613062
eventpress = self._eventpress
30623063
# The calculations are done for rotation at zero: we apply inverse
30633064
# transformation to events except when we rotate and move
3064-
if not (self._active_handle == 'C' or rotate):
3065+
move = self._active_handle == 'C'
3066+
if not move and not rotate:
30653067
inv_tr = self._get_rotation_transform().inverted()
30663068
event.xdata, event.ydata = inv_tr.transform(
30673069
[event.xdata, event.ydata])
@@ -3078,8 +3080,8 @@ def _onmove(self, event):
30783080
refx, refy = dx, dy
30793081
else:
30803082
# Add 1e-6 to avoid divided by zero error
3081-
refx = event.xdata / (eventpress.xdata + 1e-6)
3082-
refy = event.ydata / (eventpress.ydata + 1e-6)
3083+
refx = event.xdata / (eventpress.xdata or 1E-6)
3084+
refy = event.ydata / (eventpress.ydata or 1E-6)
30833085

30843086
x0, x1, y0, y1 = self._extents_on_press
30853087
# rotate an existing shape
@@ -3099,6 +3101,7 @@ def _onmove(self, event):
30993101

31003102
# Keeping the center fixed
31013103
if 'center' in state:
3104+
# hh, hw are half-height and half-width
31023105
if 'square' in state:
31033106
# when using a corner, find which reference to use
31043107
if self._active_handle in self._corner_order:
@@ -3277,14 +3280,17 @@ def extents(self, extents):
32773280

32783281
@property
32793282
def rotation(self):
3280-
"""Rotation in degree in interval [0, 45]."""
3283+
"""
3284+
Rotation in degree in interval [-45°, 45°]. The rotation is limited in
3285+
range to keep the implementation simple.
3286+
"""
32813287
return np.rad2deg(self._rotation)
32823288

32833289
@rotation.setter
32843290
def rotation(self, value):
3285-
# Restrict to a limited range of rotation [0, 45] to avoid changing
3291+
# Restrict to a limited range of rotation [-45°, 45°] to avoid changing
32863292
# order of handles
3287-
if 0 <= v 5651 alue and value <= 45:
3293+
if -45 <= value and value <= 45:
32883294
self._rotation = np.deg2rad(value)
32893295
# call extents setter to draw shape and update handles positions
32903296
self.extents = self.extents

0 commit comments

Comments
 (0)
0