{
  "cells": [
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "\n# Polygon Selector\n\nShows how to create a polygon programmatically or interactively\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "import matplotlib.pyplot as plt\n\nfrom matplotlib.widgets import PolygonSelector"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "To create the polygon programmatically\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "fig, ax = plt.subplots()\nfig.show()\n\nselector = PolygonSelector(ax, lambda *args: None)\n\n# Add three vertices\nselector.verts = [(0.1, 0.4), (0.5, 0.9), (0.3, 0.2)]"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "To create the polygon interactively\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "fig2, ax2 = plt.subplots()\nfig2.show()\n\nselector2 = PolygonSelector(ax2, lambda *args: None)\n\nprint(\"Click on the figure to create a polygon.\")\nprint(\"Press the 'esc' key to start a new polygon.\")\nprint(\"Try holding the 'shift' key to move all of the vertices.\")\nprint(\"Try holding the 'ctrl' key to move a single vertex.\")"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        ".. tags::\n\n   component: axes,\n   styling: position,\n   plot-type: line,\n   level: intermediate,\n   domain: cartography,\n   domain: geometry,\n   domain: statistics,\n\n.. admonition:: References\n\n   The use of the following functions, methods, classes and modules is shown\n   in this example:\n\n   - `matplotlib.widgets.PolygonSelector`\n\n"
      ]
    }
  ],
  "metadata": {
    "kernelspec": {
      "display_name": "Python 3",
      "language": "python",
      "name": "python3"
    },
    "language_info": {
      "codemirror_mode": {
        "name": "ipython",
        "version": 3
      },
      "file_extension": ".py",
      "mimetype": "text/x-python",
      "name": "python",
      "nbconvert_exporter": "python",
      "pygments_lexer": "ipython3",
      "version": "3.14.6"
    }
  },
  "nbformat": 4,
  "nbformat_minor": 0
}