matplotlib.widgets.LassoSelector#

class matplotlib.widgets.LassoSelector(ax, onselect=None, *, useblit=True, props=None, button=None)[source]#

Bases: _SelectorWidget

Selection curve of an arbitrary shape.

For the selector to remain responsive you must keep a reference to it.

The selected path can be used in conjunction with contains_point to select data points from an image.

In contrast to Lasso, LassoSelector is written with an interface similar to RectangleSelector and SpanSelector, and will continue to interact with the Axes until disconnected.

Example usage:

ax = plt.subplot()
ax.plot(x, y)

def onselect(verts):
    print(verts)
lasso = LassoSelector(ax, onselect)
Parameters:
axAxes

The parent Axes for the widget.

onselectfunction, optional

Whenever the lasso is released, the onselect function is called and passed the vertices of the selected path.

useblitbool, default: True

Whether to use blitting for faster drawing (if supported by the backend). See the tutorial Faster rendering by using blitting for details.

propsdict, optional

Properties with which the line is drawn, see Line2D for valid properties. Default values are defined in mpl.rcParams.

buttonMouseButton or list of MouseButton, optional

The mouse buttons used for rectangle selection. Default is None, which corresponds to all buttons.

Examples using matplotlib.widgets.LassoSelector#

Lasso Selector

Lasso Selector