On Sun, Jul 25, 2010 at 3:51 PM, Benjamin Root <ben.root@...> wrote:
> On Tue, Jul 20, 2010 at 9:21 AM, Jeff Klukas <klukas@...> wrote:
>> The documentation for hist seems to indicate that you should be able
>> to send a list of values through the 'weights' parameter in axes.hist,
>> and this worked in previous versions. In 1.0, however, this produces
>> an error. I've attached a diff (also pasted below) that I believe
>> produces the expected behavior.
>> It can be tested with:
>> plt.hist([1,2,3], weights=[1,2,3])
>> The above fails in the development version, but works with the diff.
>> Could someone add this fix?
>> || Jeff Klukas, Research Assistant, Physics
>> || University of Wisconsin -- Madison
>> || jeff.klukas@... | jeffyklukas@... | jeffklukas@...
>> || http://klukas.web.cern.ch/
>> Index: lib/matplotlib/axes.py
>> --- lib/matplotlib/axes.py (revision 8565)
>> +++ lib/matplotlib/axes.py (working copy)
>> @@ -7587,7 +7587,12 @@
>> raise ValueError("weights must be 1D or 2D")
>> - w = [np.array(wi) for wi in weights]
>> + try:
>> + weights
>> + except TypeError:
>> + w = [np.array(weights)]
>> + else:
>> + w = [np.array(wi) for wi in weights]
>> if len(w) != nx:
>> raise ValueError('weights should have the same shape as
> Good catch, Jeff. Looking over the code, looks like both the input data,
> x, and the weights get similar pre-processing done to ready it for
> histogramming. It appears that a fix was made to how x was being processed,
> but the same was not done to weights. I have a patch that fixes the
> pre-processing of weights, and also adds comments to both blocks of code to
> remind future developers to make sure changes are made to both chunks of
> The functional part of the change was to check if the first element of
> weights was an iterable or not. Before, the weights array as in the given
> example would be considered 1-element weights for 3 datasets, rather than
> 3-element weights for 1 dataset.
> Ben Root
Re-pinging on my proposed patch. Also, should it go into just the trunk, or
should it also go into the branch?