|
1 |
| - |
2 | 1 | import numpy as np
|
3 | 2 | import matplotlib.pyplot as plt
|
4 |
| -from matplotlib.mlab import normpdf |
| 3 | +from matplotlib import mlab |
5 | 4 |
|
6 | 5 |
|
7 | 6 | mu, sigma = 200, 25
|
8 | 7 | x = mu + sigma*np.random.randn(10000)
|
9 | 8 |
|
10 |
| -fig, (ax0, ax1, ax2) = plt.subplots(ncols=3, figsize=(8, 3)) |
| 9 | +fig, (ax0, ax1) = plt.subplots(ncols=2, figsize=(8, 4)) |
11 | 10 |
|
12 | 11 | n, bins, patches = ax0.hist(x, 50, normed=1, histtype='stepfilled',
|
13 | 12 | facecolor='g', alpha=0.75)
|
14 | 13 |
|
15 | 14 | # Add a line showing the expected distribution.
|
16 |
| -y = normpdf( bins, mu, sigma) |
| 15 | +y = mlab.normpdf( bins, mu, sigma) |
17 | 16 | ax0.plot(bins, y, 'k--', linewidth=1.5)
|
18 | 17 |
|
19 | 18 | ax0.set_title('stepfilled')
|
|
23 | 22 | n, bins, patches = ax1.hist(x, bins, normed=1, histtype='bar', rwidth=0.8)
|
24 | 23 | ax1.set_title('unequal bins')
|
25 | 24 |
|
26 |
| -n, bins, patches = ax2.hist(x, 50, normed=1, histtype='step', cumulative=True) |
27 |
| - |
28 |
| -# Add a line showing the expected distribution. |
29 |
| -y = normpdf( bins, mu, sigma).cumsum() |
30 |
| -y /= y[-1] |
31 |
| -ax2.plot(bins, y, 'k--', linewidth=1.5) |
32 |
| - |
33 |
| -# Create a second data-set with a smaller standard deviation. |
34 |
| -sigma2 = 15. |
35 |
| -x = mu + sigma2*np.random.randn(10000) |
36 |
| - |
37 |
| -n, bins, patches = ax2.hist(x, bins=bins, normed=1, histtype='step', cumulative=True) |
38 |
| - |
39 |
| -# Add a line showing the expected distribution. |
40 |
| -y = normpdf( bins, mu, sigma2).cumsum() |
41 |
| -y /= y[-1] |
42 |
| -ax2.plot(bins, y, 'r--', linewidth=1.5) |
43 |
| - |
44 |
| -# Overlay a reverted cumulative histogram. |
45 |
| -n, bins, patches = ax2.hist(x, bins=bins, normed=1, |
46 |
| - histtype='step', cumulative=-1) |
47 |
| - |
48 |
| -ax2.grid(True) |
49 |
| -ax2.set_ylim(0, 1.05) |
50 |
| -ax2.set_title('cumulative step') |
51 |
| - |
52 | 25 | plt.tight_layout()
|
53 | 26 | plt.show()
|
0 commit comments