Skip to content

Commit fc2ab07

Browse files
committed
Split demo that tried to do too much
1 parent 24aab97 commit fc2ab07

File tree

2 files changed

+36
-30
lines changed

2 files changed

+36
-30
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import numpy as np
2+
import matplotlib.pyplot as plt
3+
from matplotlib import mlab
4+
5+
mu, sigma = 200, 25
6+
x = mu + sigma*np.random.randn(10000)
7+
n, bins, patches = plt.hist(x, 50, normed=1, histtype='step', cumulative=True)
8+
9+
# Add a line showing the expected distribution.
10+
y = mlab.normpdf( bins, mu, sigma).cumsum()
11+
y /= y[-1]
12+
plt.plot(bins, y, 'k--', linewidth=1.5)
13+
14+
# Create a second data-set with a smaller standard deviation.
15+
sigma2 = 15.
16+
x = mu + sigma2*np.random.randn(10000)
17+
18+
n, bins, patches = plt.hist(x, bins=bins, normed=1, histtype='step', cumulative=True)
19+
20+
# Add a line showing the expected distribution.
21+
y = mlab.normpdf( bins, mu, sigma2).cumsum()
22+
y /= y[-1]
23+
plt.plot(bins, y, 'r--', linewidth=1.5)
24+
25+
# Overlay a reverted cumulative histogram.
26+
n, bins, patches = plt.hist(x, bins=bins, normed=1,
27+
histtype='step', cumulative=-1)
28+
29+
plt.grid(True)
30+
plt.ylim(0, 1.05)
31+
plt.title('cumulative step')
32+
33+
plt.show()
Lines changed: 3 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,18 @@
1-
21
import numpy as np
32
import matplotlib.pyplot as plt
4-
from matplotlib.mlab import normpdf
3+
from matplotlib import mlab
54

65

76
mu, sigma = 200, 25
87
x = mu + sigma*np.random.randn(10000)
98

10-
fig, (ax0, ax1, ax2) = plt.subplots(ncols=3, figsize=(8, 3))
9+
fig, (ax0, ax1) = plt.subplots(ncols=2, figsize=(8, 4))
1110

1211
n, bins, patches = ax0.hist(x, 50, normed=1, histtype='stepfilled',
1312
facecolor='g', alpha=0.75)
1413

1514
# Add a line showing the expected distribution.
16-
y = normpdf( bins, mu, sigma)
15+
y = mlab.normpdf( bins, mu, sigma)
1716
ax0.plot(bins, y, 'k--', linewidth=1.5)
1817

1918
ax0.set_title('stepfilled')
@@ -23,31 +22,5 @@
2322
n, bins, patches = ax1.hist(x, bins, normed=1, histtype='bar', rwidth=0.8)
2423
ax1.set_title('unequal bins')
2524

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-
5225
plt.tight_layout()
5326
plt.show()

0 commit comments

Comments
 (0)