@@ -1679,61 +1679,67 @@ def set_visible(self, visible):
1679
1679
1680
1680
class SpanSelector (_SelectorWidget ):
1681
1681
"""
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.
1683
1684
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
1685
1686
it.
1686
1687
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`.
1695
1690
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
1698
1694
1699
- """
1695
+ onselect : func(min, max), min/max are floats
1700
1696
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
1707
1699
1708
- onselect(vmin, vmax)
1700
+ minspan : float, default is None
1701
+ If selection is less than *minspan*, do not call *onselect*
1709
1702
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.
1711
1706
1712
- *direction* must be 'horizontal' or 'vertical'
1707
+ rectprops : dict, default is None
1708
+ Dictionary of :class:`matplotlib.patches.Patch` properties
1713
1709
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
1715
1712
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
1717
1715
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
1719
1721
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()
1722
1734
1723
- If *span_stays* is True, the span stays visble after making
1724
- a valid selection.
1735
+ See also: :ref:`widgets-span_selector`
1725
1736
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
+ """
1730
1738
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 ):
1735
1742
1736
- """
1737
1743
_SelectorWidget .__init__ (self , ax , onselect , useblit = useblit ,
1738
1744
button = button )
1739
1745
@@ -1763,6 +1769,7 @@ def __init__(self, ax, onselect, direction, minspan=None, useblit=False,
1763
1769
self .new_axes (ax )
1764
1770
1765
1771
def new_axes (self , ax ):
1772
+ """Set SpanSelector to operate on a new Axes"""
1766
1773
self .ax = ax
1767
1774
if self .canvas is not ax .figure .canvas :
1768
1775
if self .canvas is not None :
@@ -2479,7 +2486,8 @@ def onselect(verts):
2479
2486
2480
2487
def __init__ (self , ax , onselect = None , useblit = True , lineprops = None ,
2481
2488
button = None ):
2482
- _SelectorWidget .__init__ (self , ax , onselect , useblit = useblit , button = button )
2489
+ _SelectorWidget .__init__ (self , ax , onselect , useblit = useblit ,
2490
+ button = button )
2483
2491
2484
2492
self .verts = None
2485
2493
0 commit comments