{
  "cells": [
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "\n# 3D stem\n\nDemonstration of a stem plot in 3D, which plots vertical lines from a baseline\nto the *z*-coordinate and places a marker at the tip.\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "import matplotlib.pyplot as plt\nimport numpy as np\n\ntheta = np.linspace(0, 2*np.pi)\nx = np.cos(theta - np.pi/2)\ny = np.sin(theta - np.pi/2)\nz = theta\n\nfig, ax = plt.subplots(subplot_kw=dict(projection='3d'))\nax.stem(x, y, z)\n\nplt.show()"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "The position of the baseline can be adapted using *bottom*. The parameters\n*linefmt*, *markerfmt*, and *basefmt* control basic format properties of the\nplot. However, in contrast to `~.axes3d.Axes3D.plot` not all properties are\nconfigurable via keyword arguments. For more advanced control adapt the line\nobjects returned by `~mpl_toolkits.mplot3d.axes3d.Axes3D.stem`.\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "fig, ax = plt.subplots(subplot_kw=dict(projection='3d'))\nmarkerline, stemlines, baseline = ax.stem(\n    x, y, z, linefmt='grey', markerfmt='D', bottom=np.pi)\nmarkerline.set_markerfacecolor('none')\n\nplt.show()"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "The orientation of the stems and baseline can be changed using *orientation*.\nThis determines in which direction the stems are projected from the head\npoints, towards the *bottom* baseline.\n\nFor examples, by setting ``orientation='x'``, the stems are projected along\nthe *x*-direction, and the baseline is in the *yz*-plane.\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "fig, ax = plt.subplots(subplot_kw=dict(projection='3d'))\nmarkerline, stemlines, baseline = ax.stem(x, y, z, bottom=-1, orientation='x')\nax.set(xlabel='x', ylabel='y', zlabel='z')\n\nplt.show()"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        ".. tags::\n   plot-type: 3D, plot-type: specialty,\n   level: beginner\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
}