You are reading an old version of the documentation (v1.2.1). For the latest version see https://matplotlib.org/stable/
matplotlib

This Page

pylab_examples example code: histogram_demo.pyΒΆ

(Source code, png, hires.png, pdf)

../../_images/histogram_demo2.png
#!/usr/bin/env python
import numpy as np
import matplotlib.mlab as mlab
import matplotlib.pyplot as plt

mu, sigma = 100, 15
x = mu + sigma*np.random.randn(10000)

# the histogram of the data
n, bins, patches = plt.hist(x, 50, normed=1, facecolor='green', alpha=0.75)

# add a 'best fit' line
y = mlab.normpdf( bins, mu, sigma)
l = plt.plot(bins, y, 'r--', linewidth=1)

plt.xlabel('Smarts')
plt.ylabel('Probability')
plt.title(r'$\mathrm{Histogram\ of\ IQ:}\ \mu=100,\ \sigma=15$')
plt.axis([40, 160, 0, 0.03])
plt.grid(True)

plt.show()

Keywords: python, matplotlib, pylab, example, codex (see Search examples)