Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 5099675

Browse files
committed
Split up hist examples into two sections.
The original example was trying to do too much in one place.
1 parent ece3c57 commit 5099675

File tree

2 files changed

+40
-34
lines changed

2 files changed

+40
-34
lines changed

examples/pylab_examples/histogram_demo_extended.py renamed to examples/pylab_examples/histogram_demo_histtypes.py

Lines changed: 1 addition & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
12
import numpy as np
23
import matplotlib.pyplot as plt
34
from matplotlib.mlab import normpdf
@@ -48,38 +49,4 @@
4849
plt.grid(True)
4950
plt.ylim(0, 1.05)
5051

51-
52-
plt.figure()
53-
54-
x = mu + sigma*np.random.randn(1000,3)
55-
56-
n, bins, patches = plt.hist(x, 10, normed=1, histtype='bar',
57-
color=['crimson', 'burlywood', 'chartreuse'],
58-
label=['Crimson', 'Burlywood', 'Chartreuse'])
59-
plt.legend()
60-
61-
62-
plt.figure()
63-
n, bins, patches = plt.hist(x, 10, normed=1, histtype='bar', stacked=True)
64-
65-
plt.figure()
66-
n, bins, patches = plt.hist(x, 10, histtype='step', stacked=True, fill=True)
67-
68-
# Make a multiple-histogram of data-sets with different length.
69-
x0 = mu + sigma*np.random.randn(10000)
70-
x1 = mu + sigma*np.random.randn(7000)
71-
x2 = mu + sigma*np.random.randn(3000)
72-
73-
w0 = np.ones_like(x0)
74-
w0[:len(x0)/2] = 0.5
75-
w1 = np.ones_like(x1)
76-
w1[:len(x1)/2] = 0.5
77-
w2 = np.ones_like(x2)
78-
w2[:len(x2)/2] = 0.5
79-
80-
81-
plt.figure()
82-
83-
n, bins, patches = plt.hist( [x0,x1,x2], 10, weights=[w0, w1, w2], histtype='bar')
84-
8552
plt.show()
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import numpy as np
2+
import matplotlib.pyplot as plt
3+
4+
5+
mu, sigma = 200, 25
6+
plt.figure()
7+
8+
x = mu + sigma*np.random.randn(1000,3)
9+
10+
n, bins, patches = plt.hist(x, 10, normed=1, histtype='bar',
11+
color=['crimson', 'burlywood', 'chartreuse'],
12+
label=['Crimson', 'Burlywood', 'Chartreuse'])
13+
plt.legend()
14+
15+
16+
plt.figure()
17+
n, bins, patches = plt.hist(x, 10, normed=1, histtype='bar', stacked=True)
18+
19+
plt.figure()
20+
n, bins, patches = plt.hist(x, 10, histtype='step', stacked=True, fill=True)
21+
22+
# Make a multiple-histogram of data-sets with different length.
23+
x0 = mu + sigma*np.random.randn(10000)
24+
x1 = mu + sigma*np.random.randn(7000)
25+
x2 = mu + sigma*np.random.randn(3000)
26+
27+
w0 = np.ones_like(x0)
28+
w0[:len(x0)/2] = 0.5
29+
w1 = np.ones_like(x1)
30+
w1[:len(x1)/2] = 0.5
31+
w2 = np.ones_like(x2)
32+
w2[:len(x2)/2] = 0.5
33+
34+
35+
plt.figure()
36+
37+
n, bins, patches = plt.hist( [x0,x1,x2], 10, weights=[w0, w1, w2], histtype='bar')
38+
39+
plt.show()

0 commit comments

Comments
 (0)