.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples/line_plots/errorbars_fillbetween.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. 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_examples_line_plots_errorbars_fillbetween.py: Error bars & shaded confidence band =================================== Shaded 95% band plus asymmetric error bars — implemented with EMCPy layers only (FillBetween, LinePlot, ErrorBar). .. GENERATED FROM PYTHON SOURCE LINES 8-61 .. image-sg:: /examples/line_plots/images/sphx_glr_errorbars_fillbetween_001.png :alt: Error bars with shaded band :srcset: /examples/line_plots/images/sphx_glr_errorbars_fillbetween_001.png :class: sphx-glr-single-img .. code-block:: Python import numpy as np import matplotlib.pyplot as plt from emcpy.plots.plots import LinePlot, FillBetween, ErrorBar from emcpy.plots.create_plots import CreatePlot, CreateFigure rng = np.random.default_rng(42) x = np.linspace(0, 10, 25) y_obs = np.sin(x) + 0.2*rng.standard_normal(x.size) # Smooth model & band xx = np.linspace(0, 10, 400) y_model = np.sin(xx) band = 0.3 err_lo = 0.15 + 0.05*rng.random(x.size) err_hi = 0.20 + 0.05*rng.random(x.size) p = CreatePlot() layers = [] # Shaded confidence band fb = FillBetween(xx, y_model - band, y_model + band) fb.alpha = 0.25 fb.label = "95% band" layers.append(fb) # Model line lp = LinePlot(xx, y_model) lp.linewidth = 2 lp.label = "model" layers.append(lp) # Observations with asymmetric error bars eb = ErrorBar(x, y_obs) eb.yerr = [err_lo, err_hi] eb.fmt = "o" eb.capsize = 3 eb.label = "observations" layers.append(eb) p.plot_layers = layers p.add_title("Error bars with shaded band") p.add_xlabel("x") p.add_ylabel("value") p.add_grid() p.add_legend(loc="upper center", frameon=False) fig = CreateFigure(nrows=1, ncols=1, figsize=(7.5, 4)) fig.plot_list = [p] fig.create_figure() fig.tight_layout() plt.show() .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.085 seconds) .. _sphx_glr_download_examples_line_plots_errorbars_fillbetween.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: errorbars_fillbetween.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: errorbars_fillbetween.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: errorbars_fillbetween.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_