@@ -70,7 +70,15 @@ class Widget(object):
70
70
71
71
72
72
class AxesWidget (Widget ):
73
- """Widget that is connected to a single :class:`~matplotlib.axes.Axes`.
73
+ """Widget that is connected to a single
74
+ :class:`~matplotlib.axes.Axes`.
75
+
76
+ To guarantee that the widgets stay responsive maintain a reference
77
+ to them. This is necessary because the callback registry
78
+ maintains only weak-refs to the functions, which are member
79
+ functions of the widget. If there are no references to the widget
80
+ object it may be garbage collected which will disconnect the
81
+ callbacks.
74
82
75
83
Attributes:
76
84
@@ -112,7 +120,10 @@ def ignore(self, event):
112
120
113
121
class Button (AxesWidget ):
114
122
"""
115
- A GUI neutral button
123
+ A GUI neutral button.
124
+
125
+ For the button to remain responsive
126
+ you much keep a reference to it.
116
127
117
128
The following attributes are accessible
118
129
@@ -134,22 +145,24 @@ class Button(AxesWidget):
134
145
def __init__ (self , ax , label , image = None ,
135
146
color = '0.85' , hovercolor = '0.95' ):
136
147
"""
137
- *ax*
148
+ Parameters
149
+ ----------
150
+ ax : matplotlib.axes.Axes
138
151
The :class:`matplotlib.axes.Axes` instance the button
139
152
will be placed into.
140
153
141
- * label*
154
+ label : str
142
155
The button text. Accepts string.
143
156
144
- * image*
157
+ image : array, mpl image, PIL image
145
158
The image to place in the button, if not *None*.
146
159
Can be any legal arg to imshow (numpy array,
147
160
matplotlib Image instance, or PIL image).
148
161
149
- * color*
162
+ color : color
150
163
The color of the button when not activated
151
164
152
- * hovercolor*
165
+ hovercolor : color
153
166
The color of the button when the mouse is over it
154
167
"""
155
168
AxesWidget .__init__ (self , ax )
@@ -233,7 +246,10 @@ def disconnect(self, cid):
233
246
234
247
class Slider (AxesWidget ):
235
248
"""
236
- A slider representing a floating point range
249
+ A slider representing a floating point range.
250
+
251
+ For the slider
252
+ to remain responsive you must maintain a reference to it.
237
253
238
254
The following attributes are defined
239
255
*ax* : the slider :class:`matplotlib.axes.Axes` instance
@@ -269,28 +285,36 @@ def __init__(self, ax, label, valmin, valmax, valinit=0.5, valfmt='%1.2f',
269
285
closedmin = True , closedmax = True , slidermin = None ,
270
286
slidermax = None , dragging = True , ** kwargs ):
271
287
"""
272
- Create a slider from *valmin* to *valmax* in axes *ax*
288
+ Create a slider from *valmin* to *valmax* in axes *ax*.
289
+
290
+ additional kwargs are passed on to ``self.poly`` which is the
291
+ :class:`matplotlib.patches.Rectangle` which draws the slider
292
+ knob. See the :class:`matplotlib.patches.Rectangle` documentation
293
+ valid property names (e.g., *facecolor*, *edgecolor*, *alpha*, ...)
273
294
274
- *valinit*
295
+ Parameters
296
+ ----------
297
+ valinit : float
275
298
The slider initial position
276
299
277
- * label*
300
+ label : str
278
301
The slider label
279
302
280
- * valfmt*
281
- Used to format the slider value
303
+ valfmt : str
304
+ Used to format the slider value, fprint format string
282
305
283
- *closedmin* and *closedmax*
306
+ closedmin : bool
307
+ closedmax : bool
284
308
Indicate whether the slider interval is closed
285
309
286
- *slidermin* and *slidermax*
310
+ slidermin : float
311
+ slidermax : float
287
312
Used to constrain the value of this slider to the values
288
313
of other sliders.
289
314
290
- additional kwargs are passed on to ``self.poly`` which is the
291
- :class:`matplotlib.patches.Rectangle` which draws the slider
292
- knob. See the :class:`matplotlib.patches.Rectangle` documentation
293
- valid property names (e.g., *facecolor*, *edgecolor*, *alpha*, ...)
315
+ dragging : bool
316
+ if the silder can be dragged by the mouse
317
+
294
318
"""
295
319
AxesWidget .__init__ (self , ax )
296
320
@@ -415,7 +439,10 @@ def reset(self):
415
439
416
440
class CheckButtons (AxesWidget ):
417
441
"""
418
- A GUI neutral radio button
442
+ A GUI neutral radio button.
443
+
444
+ For the check buttons to remain responsive you much keep a
445
+ reference to this object.
419
446
420
447
The following attributes are exposed
421
448
@@ -549,6 +576,9 @@ class RadioButtons(AxesWidget):
549
576
"""
550
577
A GUI neutral radio button
551
578
579
+ For the buttons to remain responsive
580
+ you much keep a reference to this object.
581
+
552
582
The following attributes are exposed
553
583
554
584
*ax*
@@ -832,7 +862,10 @@ class Cursor(AxesWidget):
832
862
*vertOn*
833
863
Controls the visibility of the horizontal line
834
864
835
- and the visibility of the cursor itself with the *visible* attribute
865
+ and the visibility of the cursor itself with the *visible* attribute.
866
+
867
+ For the cursor to remain responsive you much keep a reference to
868
+ it.
836
869
"""
837
870
def __init__ (self , ax , horizOn = True , vertOn = True , useblit = False ,
838
871
** lineprops ):
@@ -914,7 +947,10 @@ def _update(self):
914
947
class MultiCursor (Widget ):
915
948
"""
916
949
Provide a vertical (default) and/or horizontal line cursor shared between
917
- multiple axes
950
+ multiple axes.
951
+
952
+ For the cursor to remain responsive you much keep a reference to
953
+ it.
918
954
919
955
Example usage::
920
956
@@ -1027,7 +1063,10 @@ def _update(self):
1027
1063
1028
1064
class SpanSelector (AxesWidget ):
1029
1065
"""
1030
- Select a min/max range of the x or y axes for a matplotlib Axes
1066
+ Select a min/max range of the x or y axes for a matplotlib Axes.
1067
+
1068
+ For the selector to remain responsive you much keep a reference to
1069
+ it.
1031
1070
1032
1071
Example usage::
1033
1072
@@ -1062,8 +1101,8 @@ def __init__(self, ax, onselect, direction, minspan=None, useblit=False,
1062
1101
1063
1102
Set the visible attribute to *False* if you want to turn off
1064
1103
the functionality of the span selector
1065
-
1066
- If *span_stays* is True, the span stays visble after making
1104
+
1105
+ If *span_stays* is True, the span stays visble after making
1067
1106
a valid selection.
1068
1107
"""
1069
1108
AxesWidget .__init__ (self , ax )
@@ -1085,7 +1124,7 @@ def __init__(self, ax, onselect, direction, minspan=None, useblit=False,
1085
1124
self .onmove_callback = onmove_callback
1086
1125
self .minspan = minspan
1087
1126
self .span_stays = span_stays
1088
-
1127
+
1089
1128
# Needed when dragging out of axes
1090
1129
self .buttonDown = False
1091
1130
self .prev = (0 , 0 )
@@ -1126,7 +1165,7 @@ def new_axes(self, ax):
1126
1165
visible = False ,
1127
1166
** self .rectprops )
1128
1167
self .ax .add_patch (self .stay_rect )
1129
-
1168
+
1130
1169
if not self .useblit :
1131
1170
self .ax .add_patch (self .rect )
1132
1171
@@ -1152,7 +1191,7 @@ def press(self, event):
1152
1191
self .rect .set_visible (self .visible )
1153
1192
if self .span_stays :
1154
1193
self .stay_rect .set_visible (False )
1155
-
1194
+
1156
1195
if self .direction == 'horizontal' :
1157
1196
self .pressv = event .xdata
1158
1197
else :
@@ -1168,14 +1207,14 @@ def release(self, event):
1168
1207
self .buttonDown = False
1169
1208
1170
1209
self .rect .set_visible (False )
1171
-
1210
+
1172
1211
if self .span_stays :
1173
1212
self .stay_rect .set_x (self .rect .get_x ())
1174
1213
self .stay_rect .set_y (self .rect .get_y ())
1175
1214
self .stay_rect .set_width (self .rect .get_width ())
1176
1215
self .stay_rect .set_height (self .rect .get_height ())
1177
1216
self .stay_rect .set_visible (True )
1178
-
1217
+
1179
1218
self .canvas .draw ()
1180
1219
vmin = self .pressv
1181
1220
if self .direction == 'horizontal' :
@@ -1245,7 +1284,10 @@ def onmove(self, event):
1245
1284
1246
1285
class RectangleSelector (AxesWidget ):
1247
1286
"""
1248
- Select a min/max range of the x axes for a matplotlib Axes
1287
+ Select a rectangular region of an axes.
1288
+
1289
+ For the cursor to remain responsive you much keep a reference to
1290
+ it.
1249
1291
1250
1292
Example usage::
1251
1293
@@ -1528,6 +1570,9 @@ def get_active(self):
1528
1570
class LassoSelector (AxesWidget ):
1529
1571
"""Selection curve of an arbitrary shape.
1530
1572
1573
+ For the selector to remain responsive you much keep a reference to
1574
+ it.
1575
+
1531
1576
The selected path can be used in conjunction with
1532
1577
:func:`~matplotlib.path.Path.contains_point` to select
1533
1578
data points from an image.
0 commit comments