Skip to content

Commit

Permalink
Clean up SpanSelector documentation
Browse files Browse the repository at this point in the history
Add reference to AxesWidget.active for disabling the selector.

Resolves matplotlib#7009
  • Loading branch information
LindyBalboa committed Sep 8, 2016
1 parent 4cb15ef commit 27aebe7
Showing 1 changed file with 47 additions and 39 deletions.
86 changes: 47 additions & 39 deletions lib/matplotlib/widgets.py
Expand Up @@ -1679,61 +1679,67 @@ def set_visible(self, visible):

class SpanSelector(_SelectorWidget):
"""
Select a min/max range of the x or y axes for a matplotlib Axes.
Visually select a min/max range on a single axis and call a function with
those values.
For the selector to remain responsive you must keep a reference to
To guarantee that the selector remains responsive, keep a reference to
it.
Example usage::
ax = subplot(111)
ax.plot(x,y)
def onselect(vmin, vmax):
print(vmin, vmax)
span = SpanSelector(ax, onselect, 'horizontal')
In order to turn off the SpanSelector, set `span_selector.active=False`. To
turn it back on, set `span_selector.active=True`.
*onmove_callback* is an optional callback that is called on mouse
move within the span range
Parameters
----------
ax : :class:`matplotlib.axes.Axes` object
"""
onselect : func(min, max), min/max are floats
def __init__(self, ax, onselect, direction, minspan=None, useblit=False,
rectprops=None, onmove_callback=None, span_stays=False,
button=None):
"""
Create a span selector in *ax*. When a selection is made, clear
the span and call *onselect* with::
direction : "horizontal" or "vertical"
The axis along which to draw the span selector
onselect(vmin, vmax)
minspan : float, default is None
If selection is less than *minspan*, do not call *onselect*
and clear the span.
useblit : bool, default is False
If True, use the backend-dependent blitting features for faster
canvas updates. Only available for GTKAgg right now.
*direction* must be 'horizontal' or 'vertical'
rectprops : dict, default is None
Dictionary of :class:`matplotlib.patches.Patch` properties
If *minspan* is not *None*, ignore events smaller than *minspan*
onmove_callback : func(min, max), min/max are floats, default is None
Called on mouse move while the span is being selected
The span rectangle is drawn with *rectprops*; default::
span_stays : bool, default is False
If True, the span stays visible after the mouse is released
rectprops = dict(facecolor='red', alpha=0.5)
button : int or list of ints
Determines which mouse buttons activate the span selector
1 = left mouse button
2 = center mouse button (scroll wheel)
3 = right mouse button
Set the visible attribute to *False* if you want to turn off
the functionality of the span selector
Examples
--------
>>> import matplotlib.pyplot as plt
>>> import matplotlib.widgets as mwidgets
>>> fig, ax = plt.subplots()
>>> ax.plot([1, 2, 3], [10, 50, 100])
>>> def onselect(vmin, vmax):
print(vmin, vmax)
>>> rectprops = dict(facecolor='blue', alpha=0.5)
>>> span = mwidgets.SpanSelector(ax, onselect, 'horizontal',
rectprops=rectprops)
>>> fig.show()
If *span_stays* is True, the span stays visble after making
a valid selection.
See also: :ref:`widgets-span_selector`
*button* is a list of integers indicating which mouse buttons should
be used for selection. You can also specify a single
integer if only a single button is desired. Default is *None*,
which does not limit which button can be used.
"""

Note, typically:
1 = left mouse button
2 = center mouse button (scroll wheel)
3 = right mouse button
def __init__(self, ax, onselect, direction, minspan=None, useblit=False,
rectprops=None, onmove_callback=None, span_stays=False,
button=None):

"""
_SelectorWidget.__init__(self, ax, onselect, useblit=useblit,
button=button)

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

def new_axes(self, ax):
"""Set SpanSelector to operate on a new Axes"""
self.ax = ax
if self.canvas is not ax.figure.canvas:
if self.canvas is not None:
Expand Down Expand Up @@ -2479,7 +2486,8 @@ def onselect(verts):

def __init__(self, ax, onselect=None, useblit=True, lineprops=None,
button=None):
_SelectorWidget.__init__(self, ax, onselect, useblit=useblit, button=button)
_SelectorWidget.__init__(self, ax, onselect, useblit=useblit,
button=button)

self.verts = None

Expand Down

0 comments on commit 27aebe7

Please sign in to comment.