
.. DO NOT EDIT.
.. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY.
.. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE:
.. "gallery/statistics/histogram_histtypes.py"
.. LINE NUMBERS ARE GIVEN BELOW.

.. only:: html

    .. meta::
        :keywords: codex

    .. note::
        :class: sphx-glr-download-link-note

        :ref:`Go to the end <sphx_glr_download_gallery_statistics_histogram_histtypes.py>`
        to download the full example code.

.. rst-class:: sphx-glr-example-title

.. _sphx_glr_gallery_statistics_histogram_histtypes.py:


================================================================
Demo of the histogram function's different ``histtype`` settings
================================================================

* Histogram with step curve that has a color fill.
* Histogram with step curve with no fill.
* Histogram with custom and unequal bin widths.
* Two histograms with stacked bars.

Selecting different bin counts and sizes can significantly affect the
shape of a histogram. The Astropy docs have a great section on how to
select these parameters:
http://docs.astropy.org/en/stable/visualization/histogram.html

.. GENERATED FROM PYTHON SOURCE LINES 16-52

.. code-block:: Python


    import matplotlib.pyplot as plt
    import numpy as np

    np.random.seed(19680801)

    mu_x = 200
    sigma_x = 25
    x = np.random.normal(mu_x, sigma_x, size=100)

    mu_w = 200
    sigma_w = 10
    w = np.random.normal(mu_w, sigma_w, size=100)

    fig, axs = plt.subplots(nrows=2, ncols=2)

    axs[0, 0].hist(x, 20, density=True, histtype='stepfilled', facecolor='g',
                   alpha=0.75)
    axs[0, 0].set_title('stepfilled')

    axs[0, 1].hist(x, 20, density=True, histtype='step', facecolor='g',
                   alpha=0.75)
    axs[0, 1].set_title('step')

    axs[1, 0].hist(x, density=True, histtype='barstacked', rwidth=0.8)
    axs[1, 0].hist(w, density=True, histtype='barstacked', rwidth=0.8)
    axs[1, 0].set_title('barstacked')

    # Create a histogram by providing the bin edges (unequally spaced).
    bins = [100, 150, 180, 195, 205, 220, 250, 300]
    axs[1, 1].hist(x, bins, density=True, histtype='bar', rwidth=0.8)
    axs[1, 1].set_title('bar, unequal bins')

    fig.tight_layout()
    plt.show()




.. image-sg:: /gallery/statistics/images/sphx_glr_histogram_histtypes_001.png
   :alt: stepfilled, step, barstacked, bar, unequal bins
   :srcset: /gallery/statistics/images/sphx_glr_histogram_histtypes_001.png, /gallery/statistics/images/sphx_glr_histogram_histtypes_001_2_00x.png 2.00x
   :class: sphx-glr-single-img





.. GENERATED FROM PYTHON SOURCE LINES 53-61

.. tags:: plot-type: histogram, domain: statistics, purpose: reference

.. admonition:: References

   The use of the following functions, methods, classes and modules is shown
   in this example:

   - `matplotlib.axes.Axes.hist` / `matplotlib.pyplot.hist`


.. _sphx_glr_download_gallery_statistics_histogram_histtypes.py:

.. only:: html

  .. container:: sphx-glr-footer sphx-glr-footer-example

    .. container:: sphx-glr-download sphx-glr-download-jupyter

      :download:`Download Jupyter notebook: histogram_histtypes.ipynb <histogram_histtypes.ipynb>`

    .. container:: sphx-glr-download sphx-glr-download-python

      :download:`Download Python source code: histogram_histtypes.py <histogram_histtypes.py>`

    .. container:: sphx-glr-download sphx-glr-download-zip

      :download:`Download zipped: histogram_histtypes.zip <histogram_histtypes.zip>`


.. only:: html

 .. rst-class:: sphx-glr-signature

    `Gallery generated by Sphinx-Gallery <https://sphinx-gallery.github.io>`_
