Skip to content

Commit

Permalink
Axes.hist: fix bug in handling of weights kwarg; thanks to Jeff Klukas.
Browse files Browse the repository at this point in the history
Also use weights kwarg in examples/histogram_demo_extended.

svn path=/trunk/matplotlib/; revision=8317
  • Loading branch information
efiring committed May 17, 2010
1 parent 15b6dee commit fcae31a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
15 changes: 14 additions & 1 deletion examples/pylab_examples/histogram_demo_extended.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/usr/bin/env python
import numpy as np
import pylab as P

#
Expand Down Expand Up @@ -90,8 +91,20 @@
x1 = mu + sigma*P.randn(7000)
x2 = mu + sigma*P.randn(3000)

# and exercise the weights option by arbitrarily giving the first half
# of each series only half the weight of the others:

w0 = np.ones_like(x0)
w0[:len(x0)/2] = 0.5
w1 = np.ones_like(x1)
w1[:len(x1)/2] = 0.5
w2 = np.ones_like(x2)
w0[:len(x2)/2] = 0.5



P.figure()

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

P.show()
2 changes: 1 addition & 1 deletion lib/matplotlib/axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -7364,7 +7364,7 @@ def hist(self, x, bins=10, range=None, normed=False, weights=None,
raise ValueError("color kwarg must have one color per dataset")

if weights is not None:
if isinstance(w, np.ndarray):
if isinstance(weights, np.ndarray):
w = np.array(weights)
if w.ndim == 2:
w = w.T
Expand Down

0 comments on commit fcae31a

Please sign in to comment.