Note

Go to the endto download the full example code.

Polygon Selector#

Shows how to create a polygon programmatically or interactively

importmatplotlib.pyplotaspltfrommatplotlib.widgetsimportPolygonSelector

To create the polygon programmatically

fig,ax=plt.subplots()fig.show()selector=PolygonSelector(ax,lambda*args:None)# Add three verticesselector.verts=[(0.1,0.4),(0.5,0.9),(0.3,0.2)]
polygon selector simple

To create the polygon interactively

fig2,ax2=plt.subplots()fig2.show()selector2=PolygonSelector(ax2,lambda*args:None)print("Click on the figure to create a polygon.")print("Press the 'esc' key to start a new polygon.")print("Try holding the 'shift' key to move all of the vertices.")print("Try holding the 'ctrl' key to move a single vertex.")
polygon selector simple
Click on the figure to create a polygon.Press the 'esc' key to start a new polygon.Try holding the 'shift' key to move all of the vertices.Try holding the 'ctrl' key to move a single vertex.

Tags:component: axesstyling: positionplot-type: linelevel: intermediatedomain: cartographydomain: geometrydomain: statistics

References

The use of the following functions, methods, classes and modules is shownin this example:

Gallery generated by Sphinx-Gallery