@@ -1364,61 +1364,67 @@ def set_visible(self, visible):
1364
1364
1365
1365
class SpanSelector (_SelectorWidget ):
1366
1366
"""
1367
- Select a min/max range of the x or y axes for a matplotlib Axes.
1367
+ Visually select a min/max range on a single axis and call a function with
1368
+ those values.
1368
1369
1369
- For the selector to remain responsive you must keep a reference to
1370
+ To guarantee that the selector remains responsive, keep a reference to
1370
1371
it.
1371
1372
1372
- Example usage::
1373
-
1374
- ax = subplot(111)
1375
- ax.plot(x,y)
1376
-
1377
- def onselect(vmin, vmax):
1378
- print(vmin, vmax)
1379
- span = SpanSelector(ax, onselect, 'horizontal')
1373
+ In order to turn off the SpanSelector, set `span_selector.active=False`. To
1374
+ turn it back on, set `span_selector.active=True`.
1380
1375
1381
- *onmove_callback* is an optional callback that is called on mouse
1382
- move within the span range
1376
+ Parameters
1377
+ ----------
1378
+ ax : :class:`matplotlib.axes.Axes` object
1383
1379
1384
- """
1380
+ onselect : func(min, max), min/max are floats
1385
1381
1386
- def __init__ (self , ax , onselect , direction , minspan = None , useblit = False ,
1387
- rectprops = None , onmove_callback = None , span_stays = False ,
1388
- button = None ):
1389
- """
1390
- Create a span selector in *ax*. When a selection is made, clear
1391
- the span and call *onselect* with::
1382
+ direction : "horizontal" or "vertical"
1383
+ The axis along which to draw the span selector
1392
1384
1393
- onselect(vmin, vmax)
1385
+ minspan : float, default is None
1386
+ If selection is less than *minspan*, do not call *onselect*
1394
1387
1395
- and clear the span.
1388
+ useblit : bool, default is False
1389
+ If True, use the backend-dependent blitting features for faster
1390
+ canvas updates. Only available for GTKAgg right now.
1396
1391
1397
- *direction* must be 'horizontal' or 'vertical'
1392
+ rectprops : dict, default is None
1393
+ Dictionary of :class:`matplotlib.patches.Patch` properties
1398
1394
1399
- If *minspan* is not *None*, ignore events smaller than *minspan*
1395
+ onmove_callback : func(min, max), min/max are floats, default is None
1396
+ Called on mouse move while the span is being selected
1400
1397
1401
- The span rectangle is drawn with *rectprops*; default::
1398
+ span_stays : bool, default is False
1399
+ If True, the span stays visible after the mouse is released
1402
1400
1403
- rectprops = dict(facecolor='red', alpha=0.5)
1401
+ button : int or list of ints
1402
+ Determines which mouse buttons activate the span selector
1403
+ 1 = left mouse button\n
1404
+ 2 = center mouse button (scroll wheel)\n
1405
+ 3 = right mouse button\n
1404
1406
1405
- Set the visible attribute to *False* if you want to turn off
1406
- the functionality of the span selector
1407
+ Examples
1408
+ --------
1409
+ >>> import matplotlib.pyplot as plt
1410
+ >>> import matplotlib.widgets as mwidgets
1411
+ >>> fig, ax = plt.subplots()
1412
+ >>> ax.plot([
8000
1, 2, 3], [10, 50, 100])
1413
+ >>> def onselect(vmin, vmax):
1414
+ print(vmin, vmax)
1415
+ >>> rectprops = dict(facecolor='blue', alpha=0.5)
1416
+ >>> span = mwidgets.SpanSelector(ax, onselect, 'horizontal',
1417
+ rectprops=rectprops)
1418
+ >>> fig.show()
1407
1419
1408
- If *span_stays* is True, the span stays visble after making
1409
- a valid selection.
1420
+ See also: :ref:`widgets-span_selector`
1410
1421
1411
- *button* is a list of integers indicating which mouse buttons should
1412
- be used for selection. You can also specify a single
1413
- integer if only a single button is desired. Default is *None*,
1414
- which does not limit which button can be used.
1422
+ """
1415
1423
1416
- Note, typically:
1417
- 1 = left mouse button
1418
- 2 = center mouse button (scroll wheel)
1419
- 3 = right mouse button
1424
+ def __init__ (self , ax , onselect , direction , minspan = None , useblit = False ,
1425
+ rectprops = None , onmove_callback = None , span_stays = False ,
1426
+ button = None ):
1420
1427
1421
- """
1422
1428
_SelectorWidget .__init__ (self , ax , onselect , useblit = useblit ,
1423
1429
button = button )
1424
1430
@@ -1448,6 +1454,7 @@ def __init__(self, ax, onselect, direction, minspan=None, useblit=False,
1448
1454
self .new_axes (ax )
1449
1455
1450
1456
def new_axes (self , ax ):
1457
+ """Set SpanSelector to operate on a new Axes"""
1451
1458
self .ax = ax
1452
1459
if self .canvas is not ax .figure .canvas :
1453
1460
if self .canvas is not None :
@@ -2164,7 +2171,8 @@ def onselect(verts):
2164
2171
2165
2172
def __init__ (self , ax , onselect = None , useblit = True , lineprops = None ,
2166
2173
button = None ):
2167
- _SelectorWidget .__init__ (self , ax , onselect , useblit = useblit , button = button )
2174
+ _SelectorWidget .__init__ (self , ax , onselect , useblit = useblit ,
2175
+ button = button )
2168
2176
2169
2177
self .verts = None
2170
2178
0 commit comments