Skip to content

Commit f35a330

Browse files
authored
Merge pull request #22170 from ericpre/add_docstring_example_polygon_selector
Add example to polygon selector docstring showing how to set vertices programmatically
2 parents af4046e + 08c438a commit f35a330

File tree

3 files changed

+50
-3
lines changed

3 files changed

+50
-3
lines changed

examples/widgets/polygon_selector_demo.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"""
2-
================
3-
Polygon Selector
4-
================
2+
=======================================================
3+
Select indices from a collection using polygon selector
4+
=======================================================
55
66
Shows how one can select indices of a polygon interactively.
77
"""
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
"""
2+
================
3+
Polygon Selector
4+
================
5+
6+
Shows how to create a polygon programmatically or interactively
7+
"""
8+
9+
import matplotlib.pyplot as plt
10+
from matplotlib.widgets import PolygonSelector
11+
12+
###############################################################################
13+
#
14+
# To create the polygon programmatically
15+
fig, ax = plt.subplots()
16+
fig.show()
17+
18+
selector = PolygonSelector(ax, lambda *args: None)
19+
20+
# Add three vertices
21+
selector.verts = [(0.1, 0.4), (0.5, 0.9), (0.3, 0.2)]
22+
23+
24+
###############################################################################
25+
#
26+
# To create the polygon interactively
27+
28+
fig2, ax2 = plt.subplots()
29+
fig2.show()
30+
31+
selector2 = PolygonSelector(ax2, lambda *args: None)
32+
33+
print("Click on the figure to create a polygon.")
34+
print("Press the 'esc' key to start a new polygon.")
35+
print("Try holding the 'shift' key to move all of the vertices.")
36+
print("Try holding the 'ctrl' key to move a single vertex.")
37+
38+
39+
#############################################################################
40+
#
41+
# .. admonition:: References
42+
#
43+
# The use of the following functions, methods, classes and modules is shown
44+
# in this example:
45+
#
46+
# - `matplotlib.widgets.PolygonSelector`

lib/matplotlib/widgets.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3611,6 +3611,7 @@ class PolygonSelector(_SelectorWidget):
36113611
36123612
Examples
36133613
--------
3614+
:doc:`/gallery/widgets/polygon_selector_simple`
36143615
:doc:`/gallery/widgets/polygon_selector_demo`
36153616
36163617
Notes

0 commit comments

Comments
 (0)