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

Skip to content

Commit ed9711d

Browse files
authored
Merge pull request #7047 from LindyBalboa/issue_7009
DOC: SpanSelector widget documentation
2 parents 2d1e51f + 3082e90 commit ed9711d

2 files changed

Lines changed: 47 additions & 40 deletions

File tree

lib/matplotlib/tests/test_coding_standards.py

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

lib/matplotlib/widgets.py

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

16801680
class SpanSelector(_SelectorWidget):
16811681
"""
1682-
Select a min/max range of the x or y axes for a matplotlib Axes.
1682+
Visually select a min/max range on a single axis and call a function with
1683+
those values.
16831684
1684-
For the selector to remain responsive you must keep a reference to
1685+
To guarantee that the selector remains responsive, keep a reference to
16851686
it.
16861687
1687-
Example usage::
1688-
1689-
ax = subplot(111)
1690-
ax.plot(x,y)
1691-
1692-
def onselect(vmin, vmax):
1693-
print(vmin, vmax)
1694-
span = SpanSelector(ax, onselect, 'horizontal')
1688+
In order to turn off the SpanSelector, set `span_selector.active=False`. To
1689+
turn it back on, set `span_selector.active=True`.
16951690
1696-
*onmove_callback* is an optional callback that is called on mouse
1697-
move within the span range
1691+
Parameters
1692+
----------
1693+
ax : :class:`matplotlib.axes.Axes` object
16981694
1699-
"""
1695+
onselect : func(min, max), min/max are floats
17001696
1701-
def __init__(self, ax, onselect, direction, minspan=None, useblit=False,
1702-
rectprops=None, onmove_callback=None, span_stays=False,
1703-
button=None):
1704-
"""
1705-
Create a span selector in *ax*. When a selection is made, clear
1706-
the span and call *onselect* with::
1697+
direction : "horizontal" or "vertical"
1698+
The axis along which to draw the span selector
17071699
1708-
onselect(vmin, vmax)
1700+
minspan : float, default is None
1701+
If selection is less than *minspan*, do not call *onselect*
17091702
1710-
and clear the span.
1703+
useblit : bool, default is False
1704+
If True, use the backend-dependent blitting features for faster
1705+
canvas updates. Only available for GTKAgg right now.
17111706
1712-
*direction* must be 'horizontal' or 'vertical'
1707+
rectprops : dict, default is None
1708+
Dictionary of :class:`matplotlib.patches.Patch` properties
17131709
1714-
If *minspan* is not *None*, ignore events smaller than *minspan*
1710+
onmove_callback : func(min, max), min/max are floats, default is None
1711+
Called on mouse move while the span is being selected
17151712
1716-
The span rectangle is drawn with *rectprops*; default::
1713+
span_stays : bool, default is False
1714+
If True, the span stays visible after the mouse is released
17171715
1718-
rectprops = dict(facecolor='red', alpha=0.5)
1716+
button : int or list of ints
1717+
Determines which mouse buttons activate the span selector
1718+
1 = left mouse button\n
1719+
2 = center mouse button (scroll wheel)\n
1720+
3 = right mouse button\n
17191721
1720-
Set the visible attribute to *False* if you want to turn off
1721-
the functionality of the span selector
1722+
Examples
1723+
--------
1724+
>>> import matplotlib.pyplot as plt
1725+
>>> import matplotlib.widgets as mwidgets
1726+
>>> fig, ax = plt.subplots()
1727+
>>> ax.plot([1, 2, 3], [10, 50, 100])
1728+
>>> def onselect(vmin, vmax):
1729+
print(vmin, vmax)
1730+
>>> rectprops = dict(facecolor='blue', alpha=0.5)
1731+
>>> span = mwidgets.SpanSelector(ax, onselect, 'horizontal',
1732+
rectprops=rectprops)
1733+
>>> fig.show()
17221734
1723-
If *span_stays* is True, the span stays visble after making
1724-
a valid selection.
1735+
See also: :ref:`widgets-span_selector`
17251736
1726-
*button* is a list of integers indicating which mouse buttons should
1727-
be used for selection. You can also specify a single
1728-
integer if only a single button is desired. Default is *None*,
1729-
which does not limit which button can be used.
1737+
"""
17301738

1731-
Note, typically:
1732-
1 = left mouse button
1733-
2 = center mouse button (scroll wheel)
1734-
3 = right mouse button
1739+
def __init__(self, ax, onselect, direction, minspan=None, useblit=False,
1740+
rectprops=None, onmove_callback=None, span_stays=False,
1741+
button=None):
17351742

1736-
"""
17371743
_SelectorWidget.__init__(self, ax, onselect, useblit=useblit,
17381744
button=button)
17391745

@@ -1763,6 +1769,7 @@ def __init__(self, ax, onselect, direction, minspan=None, useblit=False,
17631769
self.new_axes(ax)
17641770

17651771
def new_axes(self, ax):
1772+
"""Set SpanSelector to operate on a new Axes"""
17661773
self.ax = ax
17671774
if self.canvas is not ax.figure.canvas:
17681775
if self.canvas is not None:
@@ -2479,7 +2486,8 @@ def onselect(verts):
24792486

24802487
def __init__(self, ax, onselect=None, useblit=True, lineprops=None,
24812488
button=None):
2482-
_SelectorWidget.__init__(self, ax, onselect, useblit=useblit, button=button)
2489+
_SelectorWidget.__init__(self, ax, onselect, useblit=useblit,
2490+
button=button)
24832491

24842492
self.verts = None
24852493

0 commit comments

Comments
 (0)