{
  "cells": [
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "\n# Generate 3D polygons\n\nDemonstrate how to create polygons in 3D. Here we stack 3 hexagons.\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "import matplotlib.pyplot as plt\nimport numpy as np\n\nfrom mpl_toolkits.mplot3d.art3d import Poly3DCollection\n\n# Coordinates of a hexagon\nangles = np.linspace(0, 2 * np.pi, 6, endpoint=False)\nx = np.cos(angles)\ny = np.sin(angles)\nzs = [-3, -2, -1]\n\n# Close the hexagon by repeating the first vertex\nx = np.append(x, x[0])\ny = np.append(y, y[0])\n\nverts = []\nfor z in zs:\n    verts.append(list(zip(x*z, y*z, np.full_like(x, z))))\nverts = np.array(verts)\n\nax = plt.figure().add_subplot(projection='3d')\n\npoly = Poly3DCollection(verts, alpha=.7)\nax.add_collection3d(poly)\nax.set_aspect('equalxy')\n\nplt.show()"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        ".. tags::\n   plot-type: 3D,\n   styling: colormap,\n   level: intermediate\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
}