|
| 1 | +#!/usr/bin/env python |
| 2 | +from pylab import * |
| 3 | + |
| 4 | +mu, sigma = 100, 15 |
| 5 | +x = mu + sigma*randn(10000) |
| 6 | + |
| 7 | +# the histogram of the data |
| 8 | +n, bins, patches = hist(x, 50, normed=1, histtype='step') |
| 9 | +setp(patches, 'facecolor', 'g', 'alpha', 0.75) |
| 10 | + |
| 11 | +# add a 'best fit' line |
| 12 | +y = normpdf( bins, mu, sigma) |
| 13 | +l = plot(bins, y, 'k--', linewidth=1) |
| 14 | + |
| 15 | + |
| 16 | +# overlay the first histogram with a second one |
| 17 | +# were the data has a smaller standard deviation |
| 18 | +mu, sigma = 100, 5 |
| 19 | +x = mu + sigma*randn(10000) |
| 20 | + |
| 21 | +n, bins, patches = hist(x, 50, normed=1, histtype='step') |
| 22 | +setp(patches, 'facecolor', 'r', 'alpha', 0.25) |
| 23 | + |
| 24 | +y = normpdf( bins, mu, sigma) |
| 25 | +l = plot(bins, y, 'k--', linewidth=1) |
| 26 | + |
| 27 | +axis([40, 160, 0, 0.09]) |
| 28 | +grid(True) |
| 29 | + |
| 30 | +#savefig('histogram_demo',dpi=72) |
| 31 | +show() |
0 commit comments