
.. DO NOT EDIT.
.. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY.
.. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE:
.. "gallery/lines_bars_and_markers/step_demo.py"
.. LINE NUMBERS ARE GIVEN BELOW.

.. only:: html

    .. note::
        :class: sphx-glr-download-link-note

        Click :ref:`here <sphx_glr_download_gallery_lines_bars_and_markers_step_demo.py>`
        to download the full example code

.. rst-class:: sphx-glr-example-title

.. _sphx_glr_gallery_lines_bars_and_markers_step_demo.py:


=========
Step Demo
=========

This example demonstrates the use of `.pyplot.step` for piece-wise constant
curves. In particular, it illustrates the effect of the parameter *where*
on the step position.

The circular markers created with `.pyplot.plot` show the actual data
positions so that it's easier to see the effect of *where*.

.. GENERATED FROM PYTHON SOURCE LINES 14-34

.. code-block:: default

    import numpy as np
    import matplotlib.pyplot as plt

    x = np.arange(14)
    y = np.sin(x / 2)

    plt.step(x, y + 2, label='pre (default)')
    plt.plot(x, y + 2, 'o--', color='grey', alpha=0.3)

    plt.step(x, y + 1, where='mid', label='mid')
    plt.plot(x, y + 1, 'o--', color='grey', alpha=0.3)

    plt.step(x, y, where='post', label='post')
    plt.plot(x, y, 'o--', color='grey', alpha=0.3)

    plt.grid(axis='x', color='0.95')
    plt.legend(title='Parameter where:')
    plt.title('plt.step(where=...)')
    plt.show()




.. image:: /gallery/lines_bars_and_markers/images/sphx_glr_step_demo_001.png
    :alt: plt.step(where=...)
    :class: sphx-glr-single-img





.. GENERATED FROM PYTHON SOURCE LINES 35-37

The same behavior can be achieved by using the ``drawstyle`` parameter of
`.pyplot.plot`.

.. GENERATED FROM PYTHON SOURCE LINES 37-52

.. code-block:: default


    plt.plot(x, y + 2, drawstyle='steps', label='steps (=steps-pre)')
    plt.plot(x, y + 2, 'o--', color='grey', alpha=0.3)

    plt.plot(x, y + 1, drawstyle='steps-mid', label='steps-mid')
    plt.plot(x, y + 1, 'o--', color='grey', alpha=0.3)

    plt.plot(x, y, drawstyle='steps-post', label='steps-post')
    plt.plot(x, y, 'o--', color='grey', alpha=0.3)

    plt.grid(axis='x', color='0.95')
    plt.legend(title='Parameter drawstyle:')
    plt.title('plt.plot(drawstyle=...)')
    plt.show()




.. image:: /gallery/lines_bars_and_markers/images/sphx_glr_step_demo_002.png
    :alt: plt.plot(drawstyle=...)
    :class: sphx-glr-single-img





.. GENERATED FROM PYTHON SOURCE LINES 53-60

------------

References
""""""""""

The use of the following functions, methods, classes and modules is shown
in this example:

.. GENERATED FROM PYTHON SOURCE LINES 61-67

.. code-block:: default


    import matplotlib
    matplotlib.axes.Axes.step
    matplotlib.pyplot.step
    matplotlib.axes.Axes.plot
    matplotlib.pyplot.plot




.. rst-class:: sphx-glr-script-out

 Out:

 .. code-block:: none


    <function plot at 0x7f73be827ee0>




.. rst-class:: sphx-glr-timing

   **Total running time of the script:** ( 0 minutes  1.609 seconds)


.. _sphx_glr_download_gallery_lines_bars_and_markers_step_demo.py:


.. only :: html

 .. container:: sphx-glr-footer
    :class: sphx-glr-footer-example



  .. container:: sphx-glr-download sphx-glr-download-python

     :download:`Download Python source code: step_demo.py <step_demo.py>`



  .. container:: sphx-glr-download sphx-glr-download-jupyter

     :download:`Download Jupyter notebook: step_demo.ipynb <step_demo.ipynb>`


.. only:: html

 .. rst-class:: sphx-glr-signature

    Keywords: matplotlib code example, codex, python plot, pyplot
    `Gallery generated by Sphinx-Gallery
    <https://sphinx-gallery.readthedocs.io>`_
