matplotlib.widgets.PolygonSelector#
- classmatplotlib.widgets.PolygonSelector(ax,onselect=None,*,useblit=False,props=None,handle_props=None,grab_range=10,draw_bounding_box=False,box_handle_props=None,box_props=None)[source]#
Bases:
_SelectorWidgetSelect a polygon region of an Axes.
Place vertices with each mouse click, and make the selection by completingthe polygon (clicking on the first vertex). Once drawn individual verticescan be moved by clicking and dragging with the left mouse button, orremoved by clicking the right mouse button.
In addition, the following modifier keys can be used:
Holdctrl and click and drag a vertex to reposition it before thepolygon has been completed.
Hold theshift key and click and drag anywhere in the Axes to moveall vertices.
Press theesc key to start a new polygon.
For the selector to remain responsive you must keep a reference to it.
- Parameters:
- ax
Axes The parent Axes for the widget.
- onselectfunction, optional
When a polygon is completed or modified after completion,theonselect function is called and passed a list of the vertices as
(xdata,ydata)tuples.- useblitbool, default: False
Whether to use blitting for faster drawing (if supported by thebackend). See the tutorialFaster rendering by using blittingfor details.
- propsdict, optional
Properties with which the line is drawn, see
Line2Dfor valid properties.Default:dict(color='k',linestyle='-',linewidth=2,alpha=0.5)
- handle_propsdict, optional
Artist properties for the markers drawn at the vertices of the polygon.See the marker arguments in
Line2Dfor validproperties. Default values are defined inmpl.rcParamsexcept forthe default value ofmarkeredgecolorwhich will be the same as thecolorproperty inprops.- grab_rangefloat, default: 10
A vertex is selected (to complete the polygon or to move a vertex) ifthe mouse click is withingrab_range pixels of the vertex.
- draw_bounding_boxbool, optional
If
True, a bounding box will be drawn around the polygon selectoronce it is complete. This box can be used to move and resize theselector.- box_handle_propsdict, optional
Properties to set for the box handles. See the documentation for thehandle_props argument to
RectangleSelectorfor more info.- box_propsdict, optional
Properties to set for the box. See the documentation for thepropsargument to
RectangleSelectorfor more info.
- ax
Notes
If only one point remains after removing points, the selector reverts to anincomplete state and you can start drawing a new polygon from the existingpoint.
Examples
Polygon SelectorSelect indices from a collection using polygon selector
- propertyverts#
The polygon vertices, as a list of
(x,y)pairs.
Examples usingmatplotlib.widgets.PolygonSelector#
Select indices from a collection using polygon selector