You are reading an old version of the documentation (v2.2.2). For the latest version see
Version 2.2.2
Fork me on GitHub

Related Topics

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:

import numpy as np
import matplotlib.pyplot as plt


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)

# 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')


Keywords: matplotlib code example, codex, python plot, pyplot Gallery generated by Sphinx-Gallery