@@ -8088,7 +8088,8 @@ def hist(self, x, bins=10, range=None, normed=False, weights=None,
8088
8088
If `True`, the first element of the return tuple will
8089
8089
be the counts normalized to form a probability density, i.e.,
8090
8090
``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.
8092
8093
8093
8094
weights : array_like, shape (n, ), optional, default: None
8094
8095
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,
8300
8301
# this will automatically overwrite bins,
8301
8302
# so that each histogram uses the same bins
8302
8303
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
8303
8305
if mlast is None :
8304
8306
mlast = np .zeros (len (bins )- 1 , m .dtype )
8305
- if normed :
8307
+ if normed and not stacked :
8306
8308
db = np .diff (bins )
8307
8309
m = (m .astype (float ) / db ) / m .sum ()
8308
8310
if stacked :
8309
8311
m += mlast
8310
8312
mlast [:] = m
8311
8313
n .append (m )
8312
8314
8315
+ if stacked and normed :
8316
+ db = np .diff (bins )
8317
+ for m in n :
8318
+ m [:] = (m .astype (float ) / db ) / n [- 1 ].sum ()
8313
8319
if cumulative :
8314
8320
slc = slice (None )
8315
8321
if cbook .is_numlike (cumulative ) and cumulative < 0 :
0 commit comments