8000 Merge pull request #7047 from LindyBalboa/issue_7009 · dsblank/matplotlib@a2e56ad · GitHub
[go: up one dir, main page]

Skip to content

Commit a2e56ad

Browse files
committed
Merge pull request matplotlib#7047 from LindyBalboa/issue_7009
DOC: SpanSelector widget documentation
1 parent 6103dd6 commit a2e56ad

File tree

2 files changed

+47
-40
lines changed

2 files changed

+47
-40
lines changed

lib/matplotlib/tests/test_coding_standards.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,6 @@ def test_pep8_conformance_installed_files():
192192
'texmanager.py',
193193
'transforms.py',
194194
'type1font.py',
195-
'widgets.py',
196195
'testing/decorators.py',
197196
'testing/jpl_units/Duration.py',
198197
'testing/jpl_units/Epoch.py',

lib/matplotlib/widgets.py

Lines changed: 47 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1364,61 +1364,67 @@ def set_visible(self, visible):
13641364

13651365
class SpanSelector(_SelectorWidget):
13661366
"""
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.
13681369
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
13701371
it.
13711372
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`.
13801375
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
13831379
1384-
"""
1380+
onselect : func(min, max), min/max are floats
13851381
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
13921384
1393-
onselect(vmin, vmax)
1385+
minspan : float, default is None
1386+
If selection is less than *minspan*, do not call *onselect*
13941387
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.
13961391
1397-
*direction* must be 'horizontal' or 'vertical'
1392+
rectprops : dict, default is None
1393+
Dictionary of :class:`matplotlib.patches.Patch` properties
13981394
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
14001397
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
14021400
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
14041406
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()
14071419
1408-
If *span_stays* is True, the span stays visble after making
1409-
a valid selection.
1420+
See also: :ref:`widgets-span_selector`
14101421
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+
"""
14151423

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):
14201427

1421-
"""
14221428
_SelectorWidget.__init__(self, ax, onselect, useblit=useblit,
14231429
button=button)
14241430

@@ -1448,6 +1454,7 @@ def __init__(self, ax, onselect, direction, minspan=None, useblit=False,
14481454
self.new_axes(ax)
14491455

14501456
def new_axes(self, ax):
1457+
"""Set SpanSelector to operate on a new Axes"""
14511458
self.ax = ax
14521459
if self.canvas is not ax.figure.canvas:
14531460
if self.canvas is not None:
@@ -2164,7 +2171,8 @@ def onselect(verts):
21642171

21652172
def __init__(self, ax, onselect=None, useblit=True, lineprops=None,
21662173
button=None):
2167-
_SelectorWidget.__init__(self, ax, onselect, useblit=useblit, button=button)
2174+
_SelectorWidget.__init__(self, ax, onselect, useblit=useblit,
2175+
button=button)
21682176

21692177
self.verts = None
21702178

0 commit comments

Comments
 (0)
0