.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "gallery/widgets/polygon_selector_simple.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. meta:: :keywords: codex .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code .. rst-class:: sphx-glr-example-title .. _sphx_glr_gallery_widgets_polygon_selector_simple.py: ================ Polygon Selector ================ Shows how to create a polygon programmatically or interactively .. GENERATED FROM PYTHON SOURCE LINES 8-13 .. code-block:: Python import matplotlib.pyplot as plt from matplotlib.widgets import PolygonSelector .. GENERATED FROM PYTHON SOURCE LINES 14-15 To create the polygon programmatically .. GENERATED FROM PYTHON SOURCE LINES 16-25 .. code-block:: Python 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)] .. image-sg:: /gallery/widgets/images/sphx_glr_polygon_selector_simple_001.png :alt: polygon selector simple :srcset: /gallery/widgets/images/sphx_glr_polygon_selector_simple_001.png, /gallery/widgets/images/sphx_glr_polygon_selector_simple_001_2_00x.png 2.00x :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 26-27 To create the polygon interactively .. GENERATED FROM PYTHON SOURCE LINES 28-40 .. code-block:: Python 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.") .. image-sg:: /gallery/widgets/images/sphx_glr_polygon_selector_simple_002.png :alt: polygon selector simple :srcset: /gallery/widgets/images/sphx_glr_polygon_selector_simple_002.png, /gallery/widgets/images/sphx_glr_polygon_selector_simple_002_2_00x.png 2.00x :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none 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. .. GENERATED FROM PYTHON SOURCE LINES 41-47 .. admonition:: References The use of the following functions, methods, classes and modules is shown in this example: - `matplotlib.widgets.PolygonSelector` .. _sphx_glr_download_gallery_widgets_polygon_selector_simple.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: polygon_selector_simple.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: polygon_selector_simple.py ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_