8000 Add example to polygon selector docstring showing how to set vertices programmatically by ericpre · Pull Request #22170 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content

Add example to polygon selector docstring showing how to set vertices programmatically #22170

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions examples/widgets/polygon_selector_demo.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""
================
Polygon Selector
================
=======================================================
Select indices from a collection using polygon selector
=======================================================

Shows how one can select indices of a polygon interactively.
"""
Expand Down
46 changes: 46 additions & 0 deletions examples/widgets/polygon_selector_simple.py
8000
Original file line number Diff line numberDiff line change
@@ -0,0 +1,46 @@
"""
================
Polygon Selector
================

Shows how to create a polygon programmatically or interactively
"""

import matplotlib.pyplot as plt
from matplotlib.widgets import PolygonSelector

###############################################################################
#
# To create the polygon programmatically
fig, ax = plt.subplots()
fig.show()

selector = PolygonSelector(ax, lambda *args: None)

# Add three vertices
selector.verts = [(0.1, 0.4), (0.5, 0.9), (0.3, 0.2)]


###############################################################################
#
# 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.")


#############################################################################
#
# .. admonition:: References
#
# The use of the following functions, methods, classes and modules is shown
# in this example:
#
# - `matplotlib.widgets.PolygonSelector`
1 change: 1 addition & 0 deletions lib/matplotlib/widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -3611,6 +3611,7 @@ class PolygonSelector(_SelectorWidget):

Examples
--------
:doc:`/gallery/widgets/polygon_selector_simple`
:doc:`/gallery/widgets/polygon_selector_demo`

Notes
Expand Down
0