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

.. only:: html

    .. meta::
        :keywords: codex

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

        :ref:`Go to the end <sphx_glr_download_gallery_subplots_axes_and_figures_axhspan_demo.py>`
        to download the full example code.

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

.. _sphx_glr_gallery_subplots_axes_and_figures_axhspan_demo.py:


==============================
Draw regions that span an Axes
==============================

`~.Axes.axhspan` and `~.Axes.axvspan` draw rectangles that span the Axes in either
the horizontal or vertical direction and are bounded in the other direction. They are
often used to highlight data regions.

.. GENERATED FROM PYTHON SOURCE LINES 10-36

.. code-block:: Python


    import matplotlib.pyplot as plt
    import numpy as np

    fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(7, 3))

    np.random.seed(19680801)
    s = 2.9 * np.convolve(np.random.randn(500), np.ones(30) / 30, mode='valid')
    ax1.plot(s)
    ax1.axhspan(-1, 1, alpha=0.1)
    ax1.set(ylim=(-1.5, 1.5), title="axhspan")


    mu = 8
    sigma = 2
    x = np.linspace(0, 16, 401)
    y = np.exp(-((x-mu)**2)/(2*sigma**2))
    ax2.axvspan(mu-2*sigma, mu-sigma, color='0.95')
    ax2.axvspan(mu-sigma, mu+sigma, color='0.9')
    ax2.axvspan(mu+sigma, mu+2*sigma, color='0.95')
    ax2.axvline(mu, color='darkgrey', linestyle='--')
    ax2.plot(x, y)
    ax2.set(title="axvspan")

    plt.show()


.. GENERATED FROM PYTHON SOURCE LINES 37-55

.. admonition:: References

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

   - `matplotlib.axes.Axes.axhspan` / `matplotlib.pyplot.axhspan`
   - `matplotlib.axes.Axes.axvspan` / `matplotlib.pyplot.axvspan`


.. seealso::

   `~.Axes.axhline`, `~.Axes.axvline`, `~.Axes.axline` draw infinite lines.

.. tags::

   styling: shape
   plot-type: line
   level: beginner


.. _sphx_glr_download_gallery_subplots_axes_and_figures_axhspan_demo.py:

.. only:: html

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

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

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

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

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

    .. container:: sphx-glr-download sphx-glr-download-zip

      :download:`Download zipped: axhspan_demo.zip <axhspan_demo.zip>`


.. only:: html

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

    `Gallery generated by Sphinx-Gallery <https://sphinx-gallery.github.io>`_
