.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples/statistical_plots/histogram_kde_overlay.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_statistical_plots_histogram_kde_overlay.py: Histogram with KDE Overlay ========================== Show a normalized histogram with a smooth KDE overlay. .. GENERATED FROM PYTHON SOURCE LINES 7-46 .. image-sg:: /examples/statistical_plots/images/sphx_glr_histogram_kde_overlay_001.png :alt: Histogram + KDE (density) :srcset: /examples/statistical_plots/images/sphx_glr_histogram_kde_overlay_001.png :class: sphx-glr-single-img .. code-block:: Python import numpy as np import matplotlib.pyplot as plt from emcpy.plots.plots import Histogram, Density from emcpy.plots.create_plots import CreatePlot, CreateFigure rng = np.random.default_rng(7) data = np.concatenate([ rng.normal(-1.0, 0.7, 700), rng.normal(1.2, 0.5, 600) ]) p = CreatePlot() # Histogram (normalized) as bars hist = Histogram(data) hist.bins = 40 hist.density = True hist.alpha = 0.35 hist.label = "Histogram (density)" p.plot_layers = [hist] # KDE overlay via EMCPy Density layer (uses seaborn under the hood) kde = Density(data) kde.label = "KDE" kde.linewidth = 2 p.plot_layers.append(kde) p.add_title("Histogram + KDE (density)") p.add_xlabel("value") p.add_ylabel("density") p.add_grid() p.add_legend(loc="upper left", 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.138 seconds) .. _sphx_glr_download_examples_statistical_plots_histogram_kde_overlay.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: histogram_kde_overlay.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: histogram_kde_overlay.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: histogram_kde_overlay.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_