@@ -7451,6 +7451,12 @@ def hist(self, x, bins=10, range=None, normed=False, weights=None,
74517451 pdf, bins, patches = ax.hist(...)
74527452 print np.sum(pdf * np.diff(bins))
74537453
7454+ .. Note:: Until numpy release 1.5, the underlying numpy
7455+ histogram function was incorrect with *normed*=*True*
7456+ if bin sizes were unequal. MPL inherited that
7457+ error. It is now corrected within MPL when using
7458+ earlier numpy versions
7459+
74547460 *weights*
74557461 An array of weights, of the same shape as *x*. Each value in
74567462 *x* only contributes its associated weight towards the bin
@@ -7632,7 +7638,10 @@ def hist(self, x, bins=10, range=None, normed=False, weights=None,
76327638 xmax = max (xmax , xi .max ())
76337639 range = (xmin , xmax )
76347640
7635- hist_kwargs = dict (range = range , normed = bool (normed ))
7641+ #hist_kwargs = dict(range=range, normed=bool(normed))
7642+ # We will handle the normed kwarg within mpl until we
7643+ # get to the point of requiring numpy >= 1.5.
7644+ hist_kwargs = dict (range = range )
76367645 if np .__version__ < "1.3" : # version 1.1 and 1.2
76377646 hist_kwargs ['new' ] = True
76387647
@@ -7641,7 +7650,20 @@ def hist(self, x, bins=10, range=None, normed=False, weights=None,
76417650 # this will automatically overwrite bins,
76427651 # so that each histogram uses the same bins
76437652 m , bins = np .histogram (x [i ], bins , weights = w [i ], ** hist_kwargs )
7653+ if normed :
7654+ db = np .diff (bins )
7655+ m = (m .astype (float ) / db ) / m .sum ()
76447656 n .append (m )
7657+ if normed and db .std () > 0.01 * db .mean ():
7658+ warnings .warn ("""
7659+ This release fixes a normalization bug in the NumPy histogram
7660+ function prior to version 1.5, occuring with non-uniform
7661+ bin widths. The returned and plotted value is now a density:
7662+ n / (N * bin width),
7663+ where n is the bin count and N the total number of points.
7664+ """ )
7665+
7666+
76457667
76467668 if cumulative :
76477669 slc = slice (None )
0 commit comments