.. note:: :class: sphx-glr-download-link-note Click :ref:`here ` to download the full example code .. rst-class:: sphx-glr-example-title .. _sphx_glr_intro_scipy_auto_examples_plot_normal_distribution.py: ======================================= Normal distribution: histogram and PDF ======================================= Explore the normal distribution: a histogram built from samples and the PDF (probability density function). .. image:: /intro/scipy/auto_examples/images/sphx_glr_plot_normal_distribution_001.png :class: sphx-glr-single-img .. code-block:: python import numpy as np # Sample from a normal distribution using numpy's random number generator samples = np.random.normal(size=10000) # Compute a histogram of the sample bins = np.linspace(-5, 5, 30) histogram, bins = np.histogram(samples, bins=bins, density=True) bin_centers = 0.5*(bins[1:] + bins[:-1]) # Compute the PDF on the bin centers from scipy distribution object from scipy import stats pdf = stats.norm.pdf(bin_centers) from matplotlib import pyplot as plt plt.figure(figsize=(6, 4)) plt.plot(bin_centers, histogram, label="Histogram of samples") plt.plot(bin_centers, pdf, label="PDF") plt.legend() plt.show() **Total running time of the script:** ( 0 minutes 0.014 seconds) .. _sphx_glr_download_intro_scipy_auto_examples_plot_normal_distribution.py: .. only :: html .. container:: sphx-glr-footer :class: sphx-glr-footer-example .. container:: sphx-glr-download :download:`Download Python source code: plot_normal_distribution.py ` .. container:: sphx-glr-download :download:`Download Jupyter notebook: plot_normal_distribution.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_