Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 7b4510f

Browse files
authored
Merge pull request matplotlib#19184 from timhoffm/doc-widgets
Minor doc cleanup
2 parents c6d2581 + e9699ef commit 7b4510f

File tree

1 file changed

+35
-42
lines changed

1 file changed

+35
-42
lines changed

lib/matplotlib/widgets.py

Lines changed: 35 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ def locked(self):
6161

6262
class Widget:
6363
"""
64-
Abstract base class for GUI neutral widgets
64+
Abstract base class for GUI neutral widgets.
6565
"""
6666
drawon = True
6767
eventson = True
@@ -118,7 +118,7 @@ def __init__(self, ax):
118118

119119
def connect_event(self, event, callback):
120120
"""
121-
Connect callback with an event.
121+
Connect a callback function with an event.
122122
123123
This should be used in lieu of ``figure.canvas.mpl_connect`` since this
124124
function stores callback ids for later clean up.
@@ -277,6 +277,7 @@ def __init__(self, ax, orientation, closedmin, closedmax,
277277
self._observers = cbook.CallbackRegistry()
278278

279279
def _stepped_value(self, val):
280+
"""Return *val* coerced to closest number in the ``valstep`` grid."""
280281
if isinstance(self.valstep, Number):
281282
val = (self.valmin
282283
+ round((val - self.valmin) / self.valstep) * self.valstep)
@@ -291,17 +292,17 @@ def _stepped_value(self, val):
291292

292293
def disconnect(self, cid):
293294
"""
294-
Remove the observer with connection id *cid*
295+
Remove the observer with connection id *cid*.
295296
296297
Parameters
297298
----------
298299
cid : int
299-
Connection id of the observer to be removed
300+
Connection id of the observer to be removed.
300301
"""
301302
self._observers.disconnect(cid)
302303

303304
def reset(self):
304-
"""Reset the slider to the initial value"""
305+
"""Reset the slider to the initial value."""
305306
if self.val != self.valinit:
306307
self.set_val(self.valinit)
307308

@@ -490,7 +491,7 @@ def _format(self, val):
490491

491492
def set_val(self, val):
492493
"""
493-
Set slider value to *val*
494+
Set slider value to *val*.
494495
495496
Parameters
496497
----------
@@ -513,8 +514,7 @@ def set_val(self, val):
513514

514515
def on_changed(self, func):
515516
"""
516-
When the slider value is changed call *func* with the new
517-
slider value
517+
Connect *func* as callback function to changes of the slider value.
518518
519519
Parameters
520520
----------
@@ -525,7 +525,7 @@ def on_changed(self, func):
525525
Returns
526526
-------
527527
int
528-
Connection id (which can be used to disconnect *func*)
528+
Connection id (which can be used to disconnect *func*).
529529
"""
530530
return self._observers.connect('changed', lambda val: func(val))
531531

@@ -663,9 +663,7 @@ def __init__(
663663
self.set_val(valinit)
664664

665665
def _min_in_bounds(self, min):
666-
"""
667-
Ensure the new min value is between valmin and self.val[1]
668-
"""
666+
"""Ensure the new min value is between valmin and self.val[1]."""
669667
if min <= self.valmin:
670668
if not self.closedmin:
671669
return self.val[0]
@@ -676,9 +674,7 @@ def _min_in_bounds(self, min):
676674
return self._stepped_value(min)
677675

678676
def _max_in_bounds(self, max):
679-
"""
680-
Ensure the new max value is between valmax and self.val[0]
681-
"""
677+
"""Ensure the new max value is between valmax and self.val[0]."""
682678
if max >= self.valmax:
683679
if not self.closedmax:
684680
return self.val[1]
@@ -692,9 +688,7 @@ def _value_in_bounds(self, val):
692688
return (self._min_in_bounds(val[0]), self._max_in_bounds(val[1]))
693689

694690
def _update_val_from_pos(self, pos):
695-
"""
696-
Given a position update the *val*
697-
"""
691+
"""Update the slider value based on a given position."""
698692
idx = np.argmin(np.abs(self.val - pos))
699693
if idx == 0:
700694
val = self._min_in_bounds(pos)
@@ -742,7 +736,7 @@ def _format(self, val):
742736

743737
def set_min(self, min):
744738
"""
745-
Set the lower value of the slider to *min*
739+
Set the lower value of the slider to *min*.
746740
747741
Parameters
748742
----------
@@ -752,7 +746,7 @@ def set_min(self, min):
752746

753747
def set_max(self, max):
754748
"""
755-
Set the lower value of the slider to *max*
749+
Set the lower value of the slider to *max*.
756750
757751
Parameters
758752
----------
@@ -762,11 +756,11 @@ def set_max(self, max):
762756

763757
def set_val(self, val):
764758
"""
765-
Set slider value to *val*
759+
Set slider value to *val*.
766760
767761
Parameters
768762
----------
769-
val : tuple or arraylike of float
763+
val : tuple or array-like of float
770764
"""
771765
val = np.sort(np.asanyarray(val))
772766
if val.shape != (2,):
@@ -798,8 +792,7 @@ def set_val(self, val):
798792

799793
def on_changed(self, func):
800794
"""
801-
When the slider value is changed call *func* with the new
802-
slider value
795+
Connect *func* as callback function to changes of the slider value.
803796
804797
Parameters
805798
----------
@@ -810,7 +803,7 @@ def on_changed(self, func):
810803
Returns
811804
-------
812805
int
813-
Connection id (which can be used to disconnect *func*)
806+
Connection id (which can be used to disconnect *func*).
814807
"""
815808
return self._observers.connect('changed', lambda val: func(val))
816809

@@ -844,7 +837,7 @@ class CheckButtons(AxesWidget):
844837

845838
def __init__(self, ax, labels, actives=None):
846839
"""
847-
Add check buttons to `matplotlib.axes.Axes` instance *ax*
840+
Add check buttons to `matplotlib.axes.Axes` instance *ax*.
848841
849842
Parameters
850843
----------
@@ -1836,7 +1829,7 @@ def press(self, event):
18361829
return False
18371830

18381831
def _press(self, event):
1839-
"""Button press handler."""
1832+
"""Button press event handler."""
18401833

18411834
def release(self, event):
18421835
"""Button release event handler and validator."""
@@ -2028,7 +2021,7 @@ def ignore(self, event):
20282021
return super().ignore(event) or not self.visible
20292022

20302023
def _press(self, event):
2031-
"""on button press event"""
2024+
"""Button press event handler."""
20322025
self.rect.set_visible(self.visible)
20332026
if self.span_stays:
20342027
self.stay_rect.set_visible(False)
@@ -2046,7 +2039,7 @@ def _press(self, event):
20462039
return False
20472040

20482041
def _release(self, event):
2049-
"""on button release event"""
2042+
"""Button release event handler."""
20502043
if self.pressv is None:
20512044
return
20522045

@@ -2077,7 +2070,7 @@ def _release(self, event):
20772070
return False
20782071

20792072
def _onmove(self, event):
2080-
"""on motion notify event"""
2073+
"""Motion notify event handler."""
20812074
if self.pressv is None:
20822075
return
20832076

@@ -2156,7 +2149,7 @@ def y(self):
21562149
return self._markers.get_ydata()
21572150

21582151
def set_data(self, pts, y=None):
2159-
"""Set x and y positions of handles"""
2152+
"""Set x and y positions of handles."""
21602153
if y is not None:
21612154
x = pts
21622155
pts = np.array([x, y])
@@ -2341,7 +2334,7 @@ def onselect(eclick: MouseEvent, erelease: MouseEvent)
23412334
self._extents_on_press = None
23422335

23432336
def _press(self, event):
2344-
"""on button press event"""
2337+
"""Button press event handler."""
23452338
# make the drawn box/line visible get the click-coordinates,
23462339
# button, ...
23472340
if self.interactive and self.to_draw.get_visible():
@@ -2361,7 +2354,7 @@ def _press(self, event):
23612354
self.set_visible(self.visible)
23622355

23632356
def _release(self, event):
2364-
"""on button release event"""
2357+
"""Button release event handler."""
23652358
if not self.interactive:
23662359
self.to_draw.set_visible(False)
23672360

@@ -2404,7 +2397,7 @@ def _release(self, event):
24042397
return False
24052398

24062399
def _onmove(self, event):
2407-
"""on motion notify event if box/line is wanted"""
2400+
"""Motion notify event handler."""
24082401
# resize an existing shape
24092402
if self.active_handle and self.active_handle != 'C':
24102403
x1, x2, y1, y2 = self._extents_on_press
@@ -2492,7 +2485,7 @@ def edge_centers(self):
24922485

24932486
@property
24942487
def center(self):
2495-
"""Center of rectangle"""
2488+
"""Center of rectangle."""
24962489
x0, y0, width, height = self._rect_bbox
24972490
return x0 + width / 2., y0 + height / 2.
24982491

@@ -2537,7 +2530,7 @@ def draw_shape(self, extents):
25372530
self.to_draw.set_data([xmin, xmax], [ymin, ymax])
25382531

25392532
def _set_active_handle(self, event):
2540-
"""Set active handle based on the location of the mouse event"""
2533+
"""Set active handle based on the location of the mouse event."""
25412534
# Note: event.xdata/ydata in data coordinates, event.x/y in pixels
25422535
c_idx, c_dist = self._corner_handles.closest(event.x, event.y)
25432536
e_idx, e_dist = self._edge_handles.closest(event.x, event.y)
@@ -2802,7 +2795,7 @@ def __init__(self, ax, onselect, useblit=False,
28022795
self.set_visible(True)
28032796

28042797
def _press(self, event):
2805-
"""Button press event handler"""
2798+
"""Button press event handler."""
28062799
# Check for selection of a tool handle.
28072800
if ((self._polygon_completed or 'move_vertex' in self.state)
28082801
and len(self._xs) > 0):
@@ -2814,7 +2807,7 @@ def _press(self, event):
28142807
self._xs_at_press, self._ys_at_press = self._xs.copy(), self._ys.copy()
28152808

28162809
def _release(self, event):
2817-
"""Button release event handler"""
2810+
"""Button release event handler."""
28182811
# Release active tool handle.
28192812
if self._active_handle_idx >= 0:
28202813
self._active_handle_idx = -1
@@ -2836,7 +2829,7 @@ def _release(self, event):
28362829
self.onselect(self.verts)
28372830

28382831
def onmove(self, event):
2839-
"""Cursor move event handler and validator"""
2832+
"""Cursor move event handler and validator."""
28402833
# Method overrides _SelectorWidget.onmove because the polygon selector
28412834
# needs to process the move callback even if there is no button press.
28422835
# _SelectorWidget.onmove include logic to ignore move event if
@@ -2848,7 +2841,7 @@ def onmove(self, event):
28482841
return False
28492842

28502843
def _onmove(self, event):
2851-
"""Cursor move event handler"""
2844+
"""Cursor move event handler."""
28522845
# Move the active vertex (ToolHandle).
28532846
if self._active_handle_idx >= 0:
28542847
idx = self._active_handle_idx
@@ -2886,7 +2879,7 @@ def _onmove(self, event):
28862879
self._draw_polygon()
28872880

28882881
def _on_key_press(self, event):
2889-
"""Key press event handler"""
2882+
"""Key press event handler."""
28902883
# Remove the pending vertex if entering the 'move_vertex' or
28912884
# 'move_all' mode
28922885
if (not self._polygon_completed
@@ -2895,7 +2888,7 @@ def _on_key_press(self, event):
28952888
self._draw_polygon()
28962889

28972890
def _on_key_release(self, event):
2898-
"""Key release event handler"""
2891+
"""Key release event handler."""
28992892
# Add back the pending vertex if leaving the 'move_vertex' or
29002893
# 'move_all' mode (by checking the released key)
29012894
if (not self._polygon_completed

0 commit comments

Comments
 (0)