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

Skip to content

Commit 24aab97

Browse files
committed
Simplify example
1 parent bd2b13c commit 24aab97

1 file changed

Lines changed: 5 additions & 14 deletions

File tree

examples/pylab_examples/histogram_demo_multihist.py

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88
mu, sigma = 200, 25
99
x = mu + sigma*np.random.randn(1000,3)
1010

11+
colors = ['crimson', 'burlywood', 'chartreuse']
1112
n, bins, patches = ax0.hist(x, 10, normed=1, histtype='bar',
12-
color=['crimson', 'burlywood', 'chartreuse'],
13-
label=['Crimson', 'Burlywood', 'Chartreuse'])
13+
color=colors, label=colors)
1414
ax0.legend(prop={'size': 10})
1515
ax0.set_title('bar')
1616

@@ -22,18 +22,9 @@
2222
ax2.set_title('stepfilled')
2323

2424
# Make a multiple-histogram of data-sets with different length.
25-
x0 = mu + sigma*np.random.randn(10000)
26-
x1 = mu + sigma*np.random.randn(7000)
27-
x2 = mu + sigma*np.random.randn(3000)
28-
29-
w0 = np.ones_like(x0)
30-
w0[:len(x0)/2] = 0.5
31-
w1 = np.ones_like(x1)
32-
w1[:len(x1)/2] = 0.5
33-
w2 = np.ones_like(x2)
34-
w2[:len(x2)/2] = 0.5
35-
36-
n, bins, patches = ax3.hist( [x0,x1,x2], 10, weights=[w0, w1, w2], histtype='bar')
25+
x_multi = [mu + sigma*np.random.randn(n) for n in [10000, 5000, 2000]]
26+
27+
n, bins, patches = ax3.hist(x_multi, 10, histtype='bar')
3728
ax3.set_title('different sample sizes')
3829

3930
plt.tight_layout()

0 commit comments

Comments
 (0)