
.. DO NOT EDIT.
.. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY.
.. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE:
.. "gallery/statistics/errorbar_limits.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_statistics_errorbar_limits.py>`
        to download the full example code.

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

.. _sphx_glr_gallery_statistics_errorbar_limits.py:


==============================================
Including upper and lower limits in error bars
==============================================

In matplotlib, errors bars can have "limits". Applying limits to the
error bars essentially makes the error unidirectional. Because of that,
upper and lower limits can be applied in both the y- and x-directions
via the ``uplims``, ``lolims``, ``xuplims``, and ``xlolims`` parameters,
respectively. These parameters can be scalar or boolean arrays.

For example, if ``xlolims`` is ``True``, the x-error bars will only
extend from the data towards increasing values. If ``uplims`` is an
array filled with ``False`` except for the 4th and 7th values, all of the
y-error bars will be bidirectional, except the 4th and 7th bars, which
will extend from the data towards decreasing y-values.

.. GENERATED FROM PYTHON SOURCE LINES 18-78

.. code-block:: Python


    import matplotlib.pyplot as plt
    import numpy as np

    # example data
    x = np.array([0.5, 1.0, 1.5, 2.0, 2.5, 3.0, 3.5, 4.0, 4.5, 5.0])
    y = np.exp(-x)
    xerr = 0.1
    yerr = 0.2

    # lower & upper limits of the error
    lolims = np.array([0, 0, 1, 0, 1, 0, 0, 0, 1, 0], dtype=bool)
    uplims = np.array([0, 1, 0, 0, 0, 1, 0, 0, 0, 1], dtype=bool)
    ls = 'dotted'

    fig, ax = plt.subplots(figsize=(7, 4))

    # standard error bars
    ax.errorbar(x, y, xerr=xerr, yerr=yerr, linestyle=ls)

    # including upper limits
    ax.errorbar(x, y + 0.5, xerr=xerr, yerr=yerr, uplims=uplims,
                linestyle=ls)

    # including lower limits
    ax.errorbar(x, y + 1.0, xerr=xerr, yerr=yerr, lolims=lolims,
                linestyle=ls)

    # including upper and lower limits
    ax.errorbar(x, y + 1.5, xerr=xerr, yerr=yerr,
                lolims=lolims, uplims=uplims,
                marker='o', markersize=8,
                linestyle=ls)

    # Plot a series with lower and upper limits in both x & y
    # constant x-error with varying y-error
    xerr = 0.2
    yerr = np.full_like(x, 0.2)
    yerr[[3, 6]] = 0.3

    # mock up some limits by modifying previous data
    xlolims = lolims
    xuplims = uplims
    lolims = np.zeros_like(x)
    uplims = np.zeros_like(x)
    lolims[[6]] = True  # only limited at this index
    uplims[[3]] = True  # only limited at this index

    # do the plotting
    ax.errorbar(x, y + 2.1, xerr=xerr, yerr=yerr,
                xlolims=xlolims, xuplims=xuplims,
                uplims=uplims, lolims=lolims,
                marker='o', markersize=8,
                linestyle='none')

    # tidy up the figure
    ax.set_xlim((0, 5.5))
    ax.set_title('Errorbar upper and lower limits')
    plt.show()




.. image-sg:: /gallery/statistics/images/sphx_glr_errorbar_limits_001.png
   :alt: Errorbar upper and lower limits
   :srcset: /gallery/statistics/images/sphx_glr_errorbar_limits_001.png, /gallery/statistics/images/sphx_glr_errorbar_limits_001_2_00x.png 2.00x
   :class: sphx-glr-single-img





.. GENERATED FROM PYTHON SOURCE LINES 79-87

.. tags:: plot-type: errorbar, domain: statistics

.. admonition:: References

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

   - `matplotlib.axes.Axes.errorbar` / `matplotlib.pyplot.errorbar`


.. _sphx_glr_download_gallery_statistics_errorbar_limits.py:

.. only:: html

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

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

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

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

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

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

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


.. only:: html

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

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