Skip to content

Commit c394be8

Browse files
committed
Improve documentation
1 parent 8ce27d0 commit c394be8

File tree

3 files changed

+20
-20
lines changed

3 files changed

+20
-20
lines changed

doc/users/next_whats_new/selector_improvement.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,16 @@ Selectors improvement: rotation, aspect ratio correction and add/remove state
44
The `~matplotlib.widgets.RectangleSelector` and
55
`~matplotlib.widgets.EllipseSelector` can now be rotated interactively.
66
The rotation is enabled or disable by striking the *r* key
7-
(default value of 'rotate' in *state_modifier_keys*) or by calling
8-
*selector.add_state('rotate')*.
7+
('r' is the default key mapped to 'rotate' in *state_modifier_keys*) or by calling
8+
``selector.add_state('rotate')``.
99

1010
The aspect ratio of the axes can now be taken into account when using the
11-
"square" state. This is enable by specifying *use_data_coordinates='True'* when
11+
"square" state. This is enabled by specifying ``use_data_coordinates='True'`` when
1212
the selector is initialized.
1313

1414
In addition to changing selector state interactively using the modifier keys
1515
defined in *state_modifier_keys*, the selector state can now be changed
16-
programmatically using the *add_state* and *remove_state* method.
16+
programmatically using the *add_state* and *remove_state* methods.
1717

1818

1919
.. code-block:: python

lib/matplotlib/patches.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -780,6 +780,7 @@ def get_patch_transform(self):
780780

781781
@property
782782
def rotation_point(self):
783+
"""The rotation point of the patch."""
783784
return self._rotation_point
784785

785786
@rotation_point.setter

lib/matplotlib/widgets.py

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2074,37 +2074,34 @@ def set_handle_props(self, **handle_props):
20742074
self.update()
20752075
self._handle_props.update(handle_props)
20762076

2077-
def _validate_state(self, value):
2077+
def _validate_state(self, state):
20782078
supported_state = [
20792079
key for key, value in self._state_modifier_keys.items()
20802080
if key != 'clear' and value != 'not-applicable'
20812081
]
2082-
if value not in supported_state:
2083-
keys = ', '.join(supported_state)
2084-
raise ValueError('Setting default state must be one of the '
2085-
f'following: {keys}.')
2082+
_api.check_in_list(supported_state, state=state)
20862083

2087-
def add_state(self, value):
2084+
def add_state(self, state):
20882085
"""
20892086
Add a state to define the widget's behavior. See the
20902087
`state_modifier_keys` parameters for details.
20912088
20922089
Parameters
20932090
----------
2094-
value : str
2091+
state : str
20952092
Must be a supported state of the selector. See the
20962093
`state_modifier_keys` parameters for details.
20972094
20982095
Raises
20992096
------
21002097
ValueError
2101-
When the value is not supported by the selector.
2098+
When the state is not supported by the selector.
21022099
21032100
"""
2104-
self._validate_state(value)
2105-
self._state.add(value)
2101+
self._validate_state(state)
2102+
self._state.add(state)
21062103

2107-
def remove_state(self, value):
2104+
def remove_state(self, state):
21082105
"""
21092106
Remove a state to define the widget's behavior. See the
21102107
`state_modifier_keys` parameters for details.
@@ -2118,11 +2115,11 @@ def remove_state(self, value):
21182115
Raises
21192116
------
21202117
ValueError
2121-
When the value is not supported by the selector.
2118+
When the state is not supported by the selector.
21222119
21232120
"""
2124-
self._validate_state(value)
2125-
self._state.remove(value)
2121+
self._validate_state(state)
2122+
self._state.remove(state)
21262123

21272124

21282125
class SpanSelector(_SelectorWidget):
@@ -2193,7 +2190,7 @@ def on_select(min: float, max: float) -> Any
21932190
21942191
state_modifier_keys : dict, optional
21952192
Keyboard modifiers which affect the widget's behavior. Values
2196-
amend the defaults.
2193+
amend the defaults, which are:
21972194
21982195
- "clear": Clear the current shape, default: "escape".
21992196
@@ -2800,7 +2797,7 @@ def onselect(eclick: MouseEvent, erelease: MouseEvent)
28002797
28012798
state_modifier_keys : dict, optional
28022799
Keyboard modifiers which affect the widget's behavior. Values
2803-
amend the defaults.
2800+
amend the defaults, which are:
28042801
28052802
- "move": Move the existing shape, default: no modifier.
28062803
- "clear": Clear the current shape, default: "escape".
@@ -2855,6 +2852,8 @@ class RectangleSelector(_SelectorWidget):
28552852
props=props)
28562853
>>> fig.show()
28572854
2855+
>>> selector.add_state('square')
2856+
28582857
See also: :doc:`/gallery/widgets/rectangle_selector`
28592858
"""
28602859

0 commit comments

Comments
 (0)