.. _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 custom and unequal bin widths. 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 .. image:: /gallery/statistics/images/sphx_glr_histogram_histtypes_001.png :align: center .. code-block:: python import numpy as np import matplotlib.pyplot as plt np.random.seed(19680801) mu = 200 sigma = 25 x = np.random.normal(mu, sigma, size=100) fig, (ax0, ax1) = plt.subplots(ncols=2, figsize=(8, 4)) ax0.hist(x, 20, density=True, histtype='stepfilled', facecolor='g', alpha=0.75) ax0.set_title('stepfilled') # Create a histogram by providing the bin edges (unequally spaced). bins = [100, 150, 180, 195, 205, 220, 250, 300] ax1.hist(x, bins, density=True, histtype='bar', rwidth=0.8) ax1.set_title('unequal bins') fig.tight_layout() plt.show() .. only :: html .. container:: sphx-glr-footer :class: sphx-glr-footer-example .. container:: binder-badge .. image:: https://static.mybinder.org/badge.svg :target: https://mybinder.org/v2/gh/choldgraf/matplotlib/gh-pages?filepath=_downloads/histogram_histtypes.ipynb :width: 150 px .. container:: sphx-glr-download :download:`Download Python source code: histogram_histtypes.py ` .. container:: sphx-glr-download :download:`Download Jupyter notebook: histogram_histtypes.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_