Permalink
Browse files

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
  • Loading branch information...
efiring committed May 17, 2010
1 parent 15b6dee commit fcae31a73082acbe9af84578d051591b66a433ea
Showing with 15 additions and 2 deletions.
  1. +14 −1 examples/pylab_examples/histogram_demo_extended.py
  2. +1 −1 lib/matplotlib/axes.py
@@ -1,4 +1,5 @@
#!/usr/bin/env python
import numpy as np
import pylab as P
#
@@ -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()
@@ -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

0 comments on commit fcae31a

Please sign in to comment.