{
  "cells": [
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "\n# Mmh Donuts!!!\n\nDraw donuts (miam!) using `~.path.Path`\\s and `~.patches.PathPatch`\\es.\nThis example shows the effect of the path's orientations in a compound path.\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "import matplotlib.pyplot as plt\nimport numpy as np\n\nimport matplotlib.patches as mpatches\nimport matplotlib.path as mpath\n\n\ndef wise(v):\n    return {+1: \"CCW\", -1: \"CW\"}[v]\n\n\ndef make_circle(r):\n    t = np.arange(0, np.pi * 2.0, 0.01)\n    x = r * np.cos(t)\n    y = r * np.sin(t)\n    return np.column_stack((x, y))\n\n\nfig, ax = plt.subplots()\n\ninside_vertices = make_circle(0.5)\noutside_vertices = make_circle(1.0)\ncodes = np.full(len(inside_vertices), mpath.Path.LINETO)\ncodes[0] = mpath.Path.MOVETO\n\nfor i, (inside, outside) in enumerate(((1, 1), (1, -1), (-1, 1), (-1, -1))):\n    # Concatenate the inside and outside subpaths together, changing their\n    # order as needed\n    vertices = np.concatenate((outside_vertices[::outside],\n                               inside_vertices[::inside]))\n    # Shift the path\n    vertices += (i * 2.5, 0)\n    # The codes will be all \"LINETO\" commands, except for \"MOVETO\"s at the\n    # beginning of each subpath\n    all_codes = np.concatenate((codes, codes))\n    # Create the Path object\n    path = mpath.Path(vertices, all_codes)\n    # And plot it\n    patch = mpatches.PathPatch(path, facecolor='#885500', edgecolor='black')\n    ax.add_patch(patch)\n\n    ax.annotate(f\"Outside {wise(outside)},\\nInside {wise(inside)}\",\n                (i * 2.5, -1.5), va=\"top\", ha=\"center\")\n\nax.set(xlim=(-2, 10), ylim=(-3, 2), aspect=1, title=\"Mmm, donuts!\")\nplt.show()"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        ".. admonition:: References\n\n   The use of the following functions, methods, classes and modules is shown\n   in this example:\n\n   - `matplotlib.path`\n   - `matplotlib.path.Path`\n   - `matplotlib.patches`\n   - `matplotlib.patches.PathPatch`\n   - `matplotlib.patches.Circle`\n   - `matplotlib.axes.Axes.add_patch`\n   - `matplotlib.axes.Axes.annotate`\n   - `matplotlib.axes.Axes.set_aspect`\n   - `matplotlib.axes.Axes.set_xlim`\n   - `matplotlib.axes.Axes.set_ylim`\n   - `matplotlib.axes.Axes.set_title`\n\n.. tags::\n\n   component: patch\n   styling: shape\n   purpose: fun\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
}