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

Skip to content

Commit fcae31a

Browse files
committed
Axes.hist: fix bug in handling of weights kwarg; thanks to Jeff Klukas.
Also use weights kwarg in examples/histogram_demo_extended. svn path=/trunk/matplotlib/; revision=8317
1 parent 15b6dee commit fcae31a

2 files changed

Lines changed: 15 additions & 2 deletions

File tree

examples/pylab_examples/histogram_demo_extended.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#!/usr/bin/env python
2+
import numpy as np
23
import pylab as P
34

45
#
@@ -90,8 +91,20 @@
9091
x1 = mu + sigma*P.randn(7000)
9192
x2 = mu + sigma*P.randn(3000)
9293

94+
# and exercise the weights option by arbitrarily giving the first half
95+
# of each series only half the weight of the others:
96+
97+
w0 = np.ones_like(x0)
98+
w0[:len(x0)/2] = 0.5
99+
w1 = np.ones_like(x1)
100+
w1[:len(x1)/2] = 0.5
101+
w2 = np.ones_like(x2)
102+
w0[:len(x2)/2] = 0.5
103+
104+
105+
93106
P.figure()
94107

95-
n, bins, patches = P.hist( [x0,x1,x2], 10, histtype='bar')
108+
n, bins, patches = P.hist( [x0,x1,x2], 10, weights=[w0, w1, w2], histtype='bar')
96109

97110
P.show()

lib/matplotlib/axes.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7364,7 +7364,7 @@ def hist(self, x, bins=10, range=None, normed=False, weights=None,
73647364
raise ValueError("color kwarg must have one color per dataset")
73657365

73667366
if weights is not None:
7367-
if isinstance(w, np.ndarray):
7367+
if isinstance(weights, np.ndarray):
73687368
w = np.array(weights)
73697369
if w.ndim == 2:
73707370
w = w.T

0 commit comments

Comments
 (0)