{
  "cells": [
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "\n# Step Demo\n\nThis example demonstrates the use of `.pyplot.step` for piece-wise constant\ncurves. In particular, it illustrates the effect of the parameter *where*\non the step position.\n\n<div class=\"alert alert-info\"><h4>Note</h4><p>For the common case that you know the edge positions, use `.pyplot.stairs`\n    instead.</p></div>\n\nThe circular markers created with `.pyplot.plot` show the actual data\npositions so that it's easier to see the effect of *where*.\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "import matplotlib.pyplot as plt\nimport numpy as np\n\nx = np.arange(14)\ny = np.sin(x / 2)\n\nplt.step(x, y + 2, label='pre (default)')\nplt.plot(x, y + 2, 'o--', color='grey', alpha=0.3)\n\nplt.step(x, y + 1, where='mid', label='mid')\nplt.plot(x, y + 1, 'o--', color='grey', alpha=0.3)\n\nplt.step(x, y, where='post', label='post')\nplt.plot(x, y, 'o--', color='grey', alpha=0.3)\n\nplt.grid(axis='x', color='0.95')\nplt.legend(title='Parameter where:')\nplt.title('plt.step(where=...)')\nplt.show()"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "The same behavior can be achieved by using the ``drawstyle`` parameter of\n`.pyplot.plot`.\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "plt.plot(x, y + 2, drawstyle='steps', label='steps (=steps-pre)')\nplt.plot(x, y + 2, 'o--', color='grey', alpha=0.3)\n\nplt.plot(x, y + 1, drawstyle='steps-mid', label='steps-mid')\nplt.plot(x, y + 1, 'o--', color='grey', alpha=0.3)\n\nplt.plot(x, y, drawstyle='steps-post', label='steps-post')\nplt.plot(x, y, 'o--', color='grey', alpha=0.3)\n\nplt.grid(axis='x', color='0.95')\nplt.legend(title='Parameter drawstyle:')\nplt.title('plt.plot(drawstyle=...)')\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.axes.Axes.step` / `matplotlib.pyplot.step`\n   - `matplotlib.axes.Axes.plot` / `matplotlib.pyplot.plot`\n\n.. tags::\n\n   plot-type: step\n   plot-type: line\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
}