.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "intro/scipy/auto_examples/plot_normal_distribution.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_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). .. GENERATED FROM PYTHON SOURCE LINES 9-25 .. image-sg:: /intro/scipy/auto_examples/images/sphx_glr_plot_normal_distribution_001.png :alt: plot normal distribution :srcset: /intro/scipy/auto_examples/images/sphx_glr_plot_normal_distribution_001.png :class: sphx-glr-single-img .. code-block:: default import numpy as np import scipy as sp import matplotlib.pyplot as plt dist = sp.stats.norm(loc=0, scale=1) # standard normal distribution sample = dist.rvs(size=100000) # "random variate sample" plt.hist(sample, bins=51, # group the observations into 50 bins density=True, # normalize the frequencies label='normalized histogram') x = np.linspace(-5, 5) # possible values of the random variable plt.plot(x, dist.pdf(x), label='PDF') plt.legend() # doctest: +SKIP plt.show() .. rst-class:: sphx-glr-timing **Total running time of the script:** ( 0 minutes 0.091 seconds) .. _sphx_glr_download_intro_scipy_auto_examples_plot_normal_distribution.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_normal_distribution.py ` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_normal_distribution.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_