Weighted histograms

Hi all,
I am trying to produce a weighted histogram.
The help text for "hist" here:
http://matplotlib.sourceforge.net/api/pyplot_api.html#matplotlib.pyplot.hist
has a mention of adding weights, but it is not noted in the command line section where this should appear.

Calling:
hist(data,20,data_weights)

gives the error:
   File "/usr/local/python-2.5.2/lib/python2.5/site-packages/matplotlib/pyplot.py", line 1868, in hist
     ret = gca().hist(*args, **kwargs)
   File "/usr/local/python-2.5.2/lib/python2.5/site-packages/matplotlib/axes.py", line 6236, in hist
     normed=bool(normed), new=True)
   File "/usr/local/python-2.5.2/lib/python2.5/site-packages/numpy/lib/function_base.py", line 353, in histogram
     mn, mx = range
ValueError: too many values to unpack

Calling:
hist(data,20,weights=data_weights)

gives the error:
   File "/usr/local/python-2.5.2/lib/python2.5/site-packages/matplotlib/pyplot.py", line 1868, in hist
     ret = gca().hist(*args, **kwargs)
   File "/usr/local/python-2.5.2/lib/python2.5/site-packages/matplotlib/axes.py", line 6371, in hist
     p.update(kwargs)
   File "/usr/local/python-2.5.2/lib/python2.5/site-packages/matplotlib/artist.py", line 453, in update
     raise AttributeError('Unknown property %s'%k)
AttributeError: Unknown property weights

There's no indication in the help text of where or how to insert the weights array.

Thanks in advance,
Michael

The weights kwarg is not yet in the official release, only in svn. See

  http://matplotlib.sourceforge.net/faq/installing_faq.html#install-from-svn

The site docs and examples generally track svn, so sometimes you see
features that are not out yet. We will try and get a release out
soon....

JDH

···

On Mon, Jul 6, 2009 at 5:45 PM, Michael Cohen<mcohen@...256...> wrote:

Hi all,
I am trying to produce a weighted histogram.
The help text for "hist" here:
http://matplotlib.sourceforge.net/api/pyplot_api.html#matplotlib.pyplot.hist
has a mention of adding weights, but it is not noted in the command line
section where this should appear.

Calling:
hist(data,20,data_weights)

gives the error:
File
"/usr/local/python-2.5.2/lib/python2.5/site-packages/matplotlib/pyplot.py",
line 1868, in hist
ret = gca().hist(*args, **kwargs)
File
"/usr/local/python-2.5.2/lib/python2.5/site-packages/matplotlib/axes.py",
line 6236, in hist
normed=bool(normed), new=True)
File
"/usr/local/python-2.5.2/lib/python2.5/site-packages/numpy/lib/function_base.py",
line 353, in histogram
mn, mx = range
ValueError: too many values to unpack

Calling:
hist(data,20,weights=data_weights)

gives the error:
File
"/usr/local/python-2.5.2/lib/python2.5/site-packages/matplotlib/pyplot.py",
line 1868, in hist
ret = gca().hist(*args, **kwargs)
File
"/usr/local/python-2.5.2/lib/python2.5/site-packages/matplotlib/axes.py",
line 6371, in hist
p.update(kwargs)
File
"/usr/local/python-2.5.2/lib/python2.5/site-packages/matplotlib/artist.py",
line 453, in update
raise AttributeError('Unknown property %s'%k)
AttributeError: Unknown property weights

There's no indication in the help text of where or how to insert the
weights array.