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

Skip to content

DOC - SpanSelector widget documentation #7047

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 9, 2016
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Clean up SpanSelector documentation
Add reference to AxesWidget.active for disabling the selector.

Resolves #7009
  • Loading branch information
LindyBalboa committed Sep 8, 2016
commit f1c72a8465ed951d22e4320bd11a5628aaa58edd
86 changes: 47 additions & 39 deletions lib/matplotlib/widgets.py
Original file line number Diff line number Diff line change
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\n
2 = center mouse button (scroll wheel)\n
3 = right mouse button\n

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