MCPcopy Index your code
hub / github.com/matplotlib/matplotlib / RectangleSelector

Class RectangleSelector

lib/matplotlib/widgets.py:3378–3882  ·  view source on GitHub ↗

Select a rectangular region of an Axes. For the cursor to remain responsive you must keep a reference to it. Press and release events triggered at the same coordinates outside the selection will clear the selector, except when ``ignore_event_outside=True``. %s Exampl

Source from the content-addressed store, hash-verified

3376@_docstring.Substitution(_RECTANGLESELECTOR_PARAMETERS_DOCSTRING.replace(
3377 '__ARTIST_NAME__', 'rectangle'))
3378class RectangleSelector(_SelectorWidget):
3379 """
3380 Select a rectangular region of an Axes.
3381
3382 For the cursor to remain responsive you must keep a reference to it.
3383
3384 Press and release events triggered at the same coordinates outside the
3385 selection will clear the selector, except when
3386 ``ignore_event_outside=True``.
3387
3388 %s
3389
3390 Examples
3391 --------
3392 >>> import matplotlib.pyplot as plt
3393 >>> import matplotlib.widgets as mwidgets
3394 >>> fig, ax = plt.subplots()
3395 >>> ax.plot([1, 2, 3], [10, 50, 100])
3396 >>> def onselect(eclick, erelease):
3397 ... print(eclick.xdata, eclick.ydata)
3398 ... print(erelease.xdata, erelease.ydata)
3399 >>> props = dict(facecolor='blue', alpha=0.5)
3400 >>> rect = mwidgets.RectangleSelector(ax, onselect, interactive=True,
3401 ... props=props)
3402 >>> fig.show()
3403 >>> rect.add_state('square')
3404
3405 See also: :doc:`/gallery/widgets/rectangle_selector`
3406 """
3407
3408 def __init__(self, ax, onselect=None, *, minspanx=0,
3409 minspany=0, useblit=False,
3410 props=None, spancoords='data', button=None, grab_range=10,
3411 handle_props=None, interactive=False,
3412 state_modifier_keys=None, drag_from_anywhere=False,
3413 ignore_event_outside=False, use_data_coordinates=False):
3414 super().__init__(ax, onselect, useblit=useblit, button=button,
3415 state_modifier_keys=state_modifier_keys,
3416 use_data_coordinates=use_data_coordinates)
3417
3418 self._interactive = interactive
3419 self.drag_from_anywhere = drag_from_anywhere
3420 self.ignore_event_outside = ignore_event_outside
3421 self._rotation = 0.0
3422 self._aspect_ratio_correction = 1.0
3423
3424 # State to allow the option of an interactive selector that can't be
3425 # interactively drawn. This is used in PolygonSelector as an
3426 # interactive bounding box to allow the polygon to be easily resized
3427 self._allow_creation = True
3428
3429 if props is None:
3430 props = dict(facecolor='red', edgecolor='black',
3431 alpha=0.2, fill=True)
3432 props = {**props, 'animated': self._useblit}
3433 self._visible = props.pop('visible', self._visible)
3434 to_draw = self._init_shape(**props)
3435 self.ax.add_patch(to_draw)

Callers 1

_add_boxMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…