@@ -8088,7 +8088,8 @@ def hist(self, x, bins=10, range=None, normed=False, weights=None,
80888088 If `True`, the first element of the return tuple will
80898089 be the counts normalized to form a probability density, i.e.,
80908090 ``n/(len(x)`dbin)``, ie the integral of the histogram will sum to
8091- 1.
8091+ 1. If *stacked* is also *True*, the sum of the histograms is
8092+ normalized to 1.
80928093
80938094 weights : array_like, shape (n, ), optional, default: None
80948095 An array of weights, of the same shape as `x`. Each value in `x`
@@ -8300,16 +8301,21 @@ def hist(self, x, bins=10, range=None, normed=False, weights=None,
83008301 # this will automatically overwrite bins,
83018302 # so that each histogram uses the same bins
83028303 m , bins = np .histogram (x [i ], bins , weights = w [i ], ** hist_kwargs )
8304+ m = m .astype (float ) # causes problems later if it's an int
83038305 if mlast is None :
83048306 mlast = np .zeros (len (bins )- 1 , m .dtype )
8305- if normed :
8307+ if normed and not stacked :
83068308 db = np .diff (bins )
83078309 m = (m .astype (float ) / db ) / m .sum ()
83088310 if stacked :
83098311 m += mlast
83108312 mlast [:] = m
83118313 n .append (m )
83128314
8315+ if stacked and normed :
8316+ db = np .diff (bins )
8317+ for m in n :
8318+ m [:] = (m .astype (float ) / db ) / n [- 1 ].sum ()
83138319 if cumulative :
83148320 slc = slice (None )
83158321 if cbook .is_numlike (cumulative ) and cumulative < 0 :
0 commit comments