|
From: <ef...@us...> - 2010-09-05 00:38:51
|
Revision: 8679
http://matplotlib.svn.sourceforge.net/matplotlib/?rev=8679&view=rev
Author: efiring
Date: 2010-09-05 00:38:45 +0000 (Sun, 05 Sep 2010)
Log Message:
-----------
[3024007] Fix ancient bug in hist inherited from numpy, fixed in numpy 1.5
Modified Paths:
--------------
branches/v1_0_maint/lib/matplotlib/axes.py
Modified: branches/v1_0_maint/lib/matplotlib/axes.py
===================================================================
--- branches/v1_0_maint/lib/matplotlib/axes.py 2010-09-04 21:23:03 UTC (rev 8678)
+++ branches/v1_0_maint/lib/matplotlib/axes.py 2010-09-05 00:38:45 UTC (rev 8679)
@@ -7451,6 +7451,12 @@
pdf, bins, patches = ax.hist(...)
print np.sum(pdf * np.diff(bins))
+ .. Note:: Until numpy release 1.5, the underlying numpy
+ histogram function was incorrect with *normed*=*True*
+ if bin sizes were unequal. MPL inherited that
+ error. It is now corrected within MPL when using
+ earlier numpy versions
+
*weights*
An array of weights, of the same shape as *x*. Each value in
*x* only contributes its associated weight towards the bin
@@ -7632,7 +7638,10 @@
xmax = max(xmax, xi.max())
range = (xmin, xmax)
- hist_kwargs = dict(range=range, normed=bool(normed))
+ #hist_kwargs = dict(range=range, normed=bool(normed))
+ # We will handle the normed kwarg within mpl until we
+ # get to the point of requiring numpy >= 1.5.
+ hist_kwargs = dict(range=range)
if np.__version__ < "1.3": # version 1.1 and 1.2
hist_kwargs['new'] = True
@@ -7641,8 +7650,21 @@
# this will automatically overwrite bins,
# so that each histogram uses the same bins
m, bins = np.histogram(x[i], bins, weights=w[i], **hist_kwargs)
+ if normed:
+ db = np.diff(bins)
+ m = (m.astype(float) / db) / m.sum()
n.append(m)
+ if normed and db.std() > 0.01 * db.mean():
+ warnings.warn("""
+ This release fixes a normalization bug in the NumPy histogram
+ function prior to version 1.5, occuring with non-uniform
+ bin widths. The returned and plotted value is now a density:
+ n / (N * bin width),
+ where n is the bin count and N the total number of points.
+ """)
+
+
if cumulative:
slc = slice(None)
if cbook.is_numlike(cumulative) and cumulative < 0:
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|