.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "gallery/statistics/errorbar_features.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. meta:: :keywords: codex .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code .. rst-class:: sphx-glr-example-title .. _sphx_glr_gallery_statistics_errorbar_features.py: ======================================= Different ways of specifying error bars ======================================= Errors can be specified as a constant value (as shown in :doc:`/gallery/statistics/errorbar`). However, this example demonstrates how they vary by specifying arrays of error values. If the raw ``x`` and ``y`` data have length N, there are two options: Array of shape (N,): Error varies for each point, but the error values are symmetric (i.e. the lower and upper values are equal). Array of shape (2, N): Error varies for each point, and the lower and upper limits (in that order) are different (asymmetric case) In addition, this example demonstrates how to use log scale with error bars. .. GENERATED FROM PYTHON SOURCE LINES 23-49 .. code-block:: Python import matplotlib.pyplot as plt import numpy as np # example data x = np.arange(0.1, 4, 0.5) y = np.exp(-x) # example error bar values that vary with x-position error = 0.1 + 0.2 * x fig, (ax0, ax1) = plt.subplots(nrows=2, sharex=True) ax0.errorbar(x, y, yerr=error, fmt='-o') ax0.set_title('variable, symmetric error') # error bar values w/ different -/+ errors that # also vary with the x-position lower_error = 0.4 * error upper_error = error asymmetric_error = [lower_error, upper_error] ax1.errorbar(x, y, xerr=asymmetric_error, fmt='o') ax1.set_title('variable, asymmetric error') ax1.set_yscale('log') plt.show() .. image-sg:: /gallery/statistics/images/sphx_glr_errorbar_features_001.png :alt: variable, symmetric error, variable, asymmetric error :srcset: /gallery/statistics/images/sphx_glr_errorbar_features_001.png, /gallery/statistics/images/sphx_glr_errorbar_features_001_2_00x.png 2.00x :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 50-56 .. 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_features.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: errorbar_features.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: errorbar_features.py ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_