@@ -78,30 +78,28 @@ def get_active(self):
78
78
return self ._active
79
79
80
80
# set_active is overridden by SelectorWidgets.
81
- active = property (get_active , lambda self , active : self .set_active (active ),
82
- doc = "Is the widget active?" )
81
+ active = property (get_active , set_active , doc = "Is the widget active?" )
83
82
84
83
def ignore (self , event ):
85
- """Return True if event should be ignored.
84
+ """
85
+ Return whether *event* should be ignored.
86
86
87
- This method (or a version of it) should be called at the beginning
88
- of any event callback.
87
+ This method should be called at the beginning of any event callback.
89
88
"""
90
89
return not self .active
91
90
92
91
93
92
class AxesWidget (Widget ):
94
- """Widget that is connected to a single
95
- :class: `~matplotlib.axes.Axes`.
93
+ """
94
+ Widget that is connected to a single `~matplotlib.axes.Axes`.
96
95
97
96
To guarantee that the widget remains responsive and not garbage-collected,
98
97
a reference to the object should be maintained by the user.
99
98
100
99
This is necessary because the callback registry
101
100
maintains only weak-refs to the functions, which are member
102
101
functions of the widget. If there are no references to the widget
103
- object it may be garbage collected which will disconnect the
104
- callbacks.
102
+ object it may be garbage collected which will disconnect the callbacks.
105
103
106
104
Attributes
107
105
----------
@@ -118,7 +116,8 @@ def __init__(self, ax):
118
116
self .cids = []
119
117
120
118
def connect_event (self , event , callback ):
121
- """Connect callback with an event.
119
+ """
120
+ Connect callback with an event.
122
121
123
122
This should be used in lieu of `figure.canvas.mpl_connect` since this
124
123
function stores callback ids for later clean up.
@@ -137,7 +136,7 @@ class Button(AxesWidget):
137
136
A GUI neutral button.
138
137
139
138
For the button to remain responsive you must keep a reference to it.
140
- Call :meth:` on_clicked` to connect to the button.
139
+ Call `. on_clicked` to connect to the button.
141
140
142
141
Attributes
143
142
----------
@@ -158,18 +157,13 @@ def __init__(self, ax, label, image=None,
158
157
----------
159
158
ax : `~matplotlib.axes.Axes`
160
159
The `~.axes.Axes` instance the button will be placed into.
161
-
162
160
label : str
163
161
The button text. Accepts string.
164
-
165
- image : array, mpl image, Pillow Image
162
+ image : array-like or PIL image
166
163
The image to place in the button, if not *None*.
167
- Can be any legal arg to imshow (numpy array,
168
- matplotlib Image instance, or Pillow Image).
169
-
164
+ Supported inputs are the same as for `.Axes.imshow`.
170
165
color : color
171
166
The color of the button when not activated.
172
-
173
167
hovercolor : color
174
168
The color of the button when the mouse is over it.
175
169
"""
@@ -198,24 +192,20 @@ def __init__(self, ax, label, image=None,
198
192
self ._lastcolor = color
199
193
200
194
def _click (self , event ):
201
- if self .ignore (event ):
202
- return
203
- if event .inaxes != self .ax :
204
- return
205
- if not self .eventson :
195
+ if (self .ignore (event )
196
+ or event .inaxes != self .ax
197
+ or not self .eventson ):
206
198
return
207
199
if event .canvas .mouse_grabber != self .ax :
208
200
event .canvas .grab_mouse (self .ax )
209
201
210
202
def _release (self , event ):
211
- if self .ignore (event ):
212
- return
213
- if event .canvas .mouse_grabber != self .ax :
203
+ if (self .ignore (event )
204
+ or event .canvas .mouse_grabber != self .ax ):
214
205
return
215
206
event .canvas .release_mouse (self .ax )
216
- if not self .eventson :
217
- return
218
- if event .inaxes != self .ax :
207
+ if (not self .eventson
208
+ or event .inaxes != self .ax ):
219
209
return
220
210
for cid , func in self .observers .items ():
221
211
func (event )
@@ -622,9 +612,8 @@ def set_active(self, index):
622
612
Raises ValueError if *index* is invalid.
623
613
624
614
Callbacks will be triggered if :attr:`eventson` is True.
625
-
626
615
"""
627
- if 0 > index >= len (self .labels ):
616
+ if not 0 <= index < len (self .labels ):
628
617
raise ValueError ("Invalid CheckButton index: %d" % index )
629
618
630
619
l1 , l2 = self .lines [index ]
@@ -823,12 +812,12 @@ def _keypress(self, event):
823
812
self .cursor_index = 0
824
813
elif key == "end" :
825
814
self .cursor_index = len (self .text )
826
- elif ( key == "backspace" ) :
815
+ elif key == "backspace" :
827
816
if self .cursor_index != 0 :
828
817
self .text = (self .text [:self .cursor_index - 1 ] +
829
818
self .text [self .cursor_index :])
830
819
self .cursor_index -= 1
831
- elif ( key == "delete" ) :
820
+ elif key == "delete" :
832
821
if self .cursor_index != len (self .text ):
833
822
self .text = (self .text [:self .cursor_index ] +
834
823
self .text [self .cursor_index + 1 :])
@@ -871,9 +860,8 @@ def begin_typing(self, x):
871
860
872
861
def stop_typing (self ):
873
862
notifysubmit = False
874
- # because _notify_submit_users might throw an error in the
875
- # user's code, we only want to call it once we've already done
876
- # our cleanup.
863
+ # Because _notify_submit_users might throw an error in the user's code,
864
+ # we only want to call it once we've already done our cleanup.
877
865
if self .capturekeystrokes :
878
866
# Check for toolmanager handling the keypress
879
867
if self .ax .figure .canvas .manager .key_press_handler_id is not None :
@@ -988,7 +976,6 @@ class RadioButtons(AxesWidget):
988
976
989
977
Connect to the RadioButtons with the :meth:`on_clicked` method.
990
978
991
-
992
979
Attributes
993
980
----------
994
981
ax
@@ -1001,8 +988,8 @@ class RadioButtons(AxesWidget):
1001
988
A list of `~.patches.Circle` instances defining the buttons.
1002
989
value_selected : str
1003
990
The label text of the currently selected button.
1004
-
1005
991
"""
992
+
1006
993
def __init__ (self , ax , labels , active = 0 , activecolor = 'blue' ):
1007
994
"""
1008
995
Add radio buttons to an `~.axes.Axes`.
@@ -1348,8 +1335,7 @@ class MultiCursor(Widget):
1348
1335
Provide a vertical (default) and/or horizontal line cursor shared between
1349
1336
multiple axes.
1350
1337
1351
- For the cursor to remain responsive you must keep a reference to
1352
- it.
1338
+ For the cursor to remain responsive you must keep a reference to it.
1353
1339
1354
1340
Example usage::
1355
1341
@@ -1511,54 +1497,42 @@ def connect_default_events(self):
1511
1497
self .connect_event ('scroll_event' , self .on_scroll )
1512
1498
1513
1499
def ignore (self , event ):
1514
- """return *True* if *event* should be ignored"""
1500
+ # docstring inherited
1515
1501
if not self .active or not self .ax .get_visible ():
1516
1502
return True
1517
-
1518
1503
# If canvas was locked
1519
1504
if not self .canvas .widgetlock .available (self ):
1520
1505
return True
1521
-
1522
1506
if not hasattr (event , 'button' ):
1523
1507
event .button = None
1524
-
1525
1508
# Only do rectangle selection if event was triggered
1526
1509
# with a desired button
1527
- if self .validButtons is not None :
1528
- if event .button not in self .validButtons :
1529
- return True
1530
-
1510
+ if (self .validButtons is not None
1511
+ and event .button not in self .validButtons ):
1512
+ return True
1531
1513
# If no button was pressed yet ignore the event if it was out
1532
1514
# of the axes
1533
1515
if self .eventpress is None :
1534
1516
return event .inaxes != self .ax
1535
-
1536
- # If a button was pressed, check if the release-button is the
1537
- # same.
1517
+ # If a button was pressed, check if the release-button is the same.
1538
1518
if event .button == self .eventpress .button :
1539
1519
return False
1540
-
1541
- # If a button was pressed, check if the release-button is the
1542
- # same.
1520
+ # If a button was pressed, check if the release-button is the same.
1543
1521
return (event .inaxes != self .ax or
1544
1522
event .button != self .eventpress .button )
1545
1523
1546
1524
def update (self ):
1547
- """draw using newfangled blit or oldfangled draw depending on
1548
- useblit
1549
-
1525
+ """
1526
+ Draw using blit() or draw_idle() depending on ``self.useblit``.
1550
1527
"""
1551
1528
if not self .ax .get_visible ():
1552
1529
return False
1553
-
1554
1530
if self .useblit :
1555
1531
if self .background is not None :
1556
1532
self .canvas .restore_region (self .background )
1557
1533
for artist in self .artists :
1558
1534
self .ax .draw_artist (artist )
1559
-
1560
1535
self .canvas .blit (self .ax .bbox )
1561
-
1562
1536
else :
1563
1537
self .canvas .draw_idle ()
1564
1538
return False
@@ -1608,7 +1582,6 @@ def press(self, event):
1608
1582
1609
1583
def _press (self , event ):
1610
1584
"""Button press handler"""
1611
- pass
1612
1585
1613
1586
def release (self , event ):
1614
1587
"""Button release event handler and validator"""
@@ -1624,7 +1597,6 @@ def release(self, event):
1624
1597
1625
1598
def _release (self , event ):
1626
1599
"""Button release event handler"""
1627
- pass
1628
1600
1629
1601
def onmove (self , event ):
1630
1602
"""Cursor move event handler and validator"""
@@ -1636,7 +1608,6 @@ def onmove(self, event):
1636
1608
1637
1609
def _onmove (self , event ):
1638
1610
"""Cursor move event handler"""
1639
- pass
1640
1611
1641
1612
def on_scroll (self , event ):
1642
1613
"""Mouse scroll event handler and validator"""
@@ -1645,7 +1616,6 @@ def on_scroll(self, event):
1645
1616
1646
1617
def _on_scroll (self , event ):
1647
1618
"""Mouse scroll event handler"""
1648
- pass
1649
1619
1650
1620
def on_key_press (self , event ):
1651
1621
"""Key press event handler and validator for all selection widgets"""
@@ -1665,7 +1635,6 @@ def on_key_press(self, event):
1665
1635
def _on_key_press (self , event ):
1666
1636
"""Key press event handler - use for widget-specific key press actions.
1667
1637
"""
1668
- pass
1669
1638
1670
1639
def on_key_release (self , event ):
1671
1640
"""Key release event handler and validator."""
@@ -1742,7 +1711,6 @@ class SpanSelector(_SelectorWidget):
1742
1711
>>> fig.show()
1743
1712
1744
1713
See also: :doc:`/gallery/widgets/span_selector`
1745
-
1746
1714
"""
1747
1715
1748
1716
def __init__ (self , ax , onselect , direction , minspan = None , useblit = False ,
@@ -1776,7 +1744,7 @@ def __init__(self, ax, onselect, direction, minspan=None, useblit=False,
1776
1744
self .new_axes (ax )
1777
1745
1778
1746
def new_axes (self , ax ):
1779
- """Set SpanSelector to operate on a new Axes"""
1747
+ """Set SpanSelector to operate on a new Axes. """
1780
1748
self .ax = ax
1781
1749
if self .canvas is not ax .figure .canvas :
1782
1750
if self .canvas is not None :
@@ -1809,7 +1777,7 @@ def new_axes(self, ax):
1809
1777
self .artists = [self .rect ]
1810
1778
1811
1779
def ignore (self , event ):
1812
- """return *True* if *event* should be ignored"""
1780
+ # docstring inherited
1813
1781
return _SelectorWidget .ignore (self , event ) or not self .visible
1814
1782
1815
1783
def _press (self , event ):
@@ -1912,7 +1880,8 @@ def _set_span_xy(self, event):
1912
1880
1913
1881
1914
1882
class ToolHandles :
1915
- """Control handles for canvas tools.
1883
+ """
1884
+ Control handles for canvas tools.
1916
1885
1917
1886
Parameters
1918
1887
----------
@@ -1928,7 +1897,6 @@ class ToolHandles:
1928
1897
1929
1898
def __init__ (self , ax , x , y , marker = 'o' , marker_props = None , useblit = True ):
1930
1899
self .ax = ax
1931
-
1932
1900
props = dict (marker = marker , markersize = 7 , mfc = 'w' , ls = 'none' ,
1933
1901
alpha = 0.5 , visible = False , label = '_nolegend_' )
1934
1902
props .update (marker_props if marker_props is not None else {})
@@ -1972,8 +1940,7 @@ class RectangleSelector(_SelectorWidget):
1972
1940
"""
1973
1941
Select a rectangular region of an axes.
1974
1942
1975
- For the cursor to remain responsive you must keep a reference to
1976
- it.
1943
+ For the cursor to remain responsive you must keep a reference to it.
1977
1944
1978
1945
Example usage::
1979
1946
@@ -2080,9 +2047,9 @@ def __init__(self, ax, onselect, drawtype='box',
2080
2047
self .visible = True
2081
2048
self .interactive = interactive
2082
2049
2083
- if drawtype == 'none' :
2084
- drawtype = 'line' # draw a line but make it
2085
- self .visible = False # invisible
2050
+ if drawtype == 'none' : # draw a line but make it invisible
2051
+ drawtype = 'line'
2052
+ self .visible = False
2086
2053
2087
2054
if drawtype == 'box' :
2088
2055
if rectprops is None :
@@ -2400,8 +2367,7 @@ class EllipseSelector(RectangleSelector):
2400
2367
"""
2401
2368
Select an elliptical region of an axes.
2402
2369
2403
- For the cursor to remain responsive you must keep a reference to
2404
- it.
2370
+ For the cursor to remain responsive you must keep a reference to it.
2405
2371
2406
2372
Example usage::
2407
2373
@@ -2507,7 +2473,6 @@ def onselect(verts):
2507
2473
- 1 = left mouse button
2508
2474
- 2 = center mouse button (scroll wheel)
2509
2475
- 3 = right mouse button
2510
-
2511
2476
"""
2512
2477
2513
2478
def __init__ (self , ax , onselect = None , useblit = True , lineprops = None ,
@@ -2555,7 +2520,8 @@ def _onmove(self, event):
2555
2520
2556
2521
2557
2522
class PolygonSelector (_SelectorWidget ):
2558
- """Select a polygon region of an axes.
2523
+ """
2524
+ Select a polygon region of an axes.
2559
2525
2560
2526
Place vertices with each mouse click, and make the selection by completing
2561
2527
the polygon (clicking on the first vertex). Hold the *ctrl* key and click
@@ -2757,18 +2723,13 @@ def _draw_polygon(self):
2757
2723
2758
2724
@property
2759
2725
def verts (self ):
2760
- """Get the polygon vertices.
2761
-
2762
- Returns
2763
- -------
2764
- list
2765
- A list of the vertices of the polygon as ``(xdata, ydata)`` tuples.
2766
- """
2726
+ """The polygon vertices, as a list of ``(x, y)`` pairs."""
2767
2727
return list (zip (self ._xs [:- 1 ], self ._ys [:- 1 ]))
2768
2728
2769
2729
2770
2730
class Lasso (AxesWidget ):
2771
- """Selection curve of an arbitrary shape.
2731
+ """
2732
+ Selection curve of an arbitrary shape.
2772
2733
2773
2734
The selected path can be used in conjunction with
2774
2735
:func:`~matplotlib.path.Path.contains_point` to select data points
0 commit comments