@@ -6080,8 +6080,10 @@ def hist(self, x, bins=None, range=None, density=None, weights=None,
6080
6080
else :
6081
6081
hist_kwargs = dict (range = bin_range )
6082
6082
6083
- n = []
6083
+ # List to store all the top coordinates of the histograms
6084
+ tops = []
6084
6085
mlast = None
6086
+ # Loop through datasets
6085
6087
for i in xrange (nx ):
6086
6088
# this will automatically overwrite bins,
6087
6089
# so that each histogram uses the same bins
@@ -6097,21 +6099,23 @@ def hist(self, x, bins=None, range=None, density=None, weights=None,
6097
6099
mlast = np .zeros (len (bins )- 1 , m .dtype )
6098
6100
m += mlast
6099
6101
mlast [:] = m
6100
- n .append (m )
6102
+ tops .append (m )
6101
6103
6104
+ # If a stacked density plot, normalize so the area of all the stacked
6105
+ # histograms together is 1
6102
6106
if stacked and density :
6103
6107
db = np .diff (bins )
6104
- for m in n :
6105
- m [:] = (m .astype (float ) / db ) / n [- 1 ].sum ()
6108
+ for m in tops :
6109
+ m [:] = (m .astype (float ) / db ) / tops [- 1 ].sum ()
6106
6110
if cumulative :
6107
6111
slc = slice (None )
6108
6112
if cbook .is_numlike (cumulative ) and cumulative < 0 :
6109
6113
slc = slice (None , None , - 1 )
6110
6114
6111
6115
if density :
6112
- n = [(m * np .diff (bins ))[slc ].cumsum ()[slc ] for m in n ]
6116
+ tops = [(m * np .diff (bins ))[slc ].cumsum ()[slc ] for m in tops ]
6113
6117
else :
6114
- n = [m [slc ].cumsum ()[slc ] for m in n ]
6118
+ tops = [m [slc ].cumsum ()[slc ] for m in tops ]
6115
6119
6116
6120
patches = []
6117
6121
@@ -6129,7 +6133,7 @@ def hist(self, x, bins=None, range=None, density=None, weights=None,
6129
6133
6130
6134
if rwidth is not None :
6131
6135
dr = np .clip (rwidth , 0 , 1 )
6132
- elif (len (n ) > 1 and
6136
+ elif (len (tops ) > 1 and
6133
6137
((not stacked ) or rcParams ['_internal.classic_mode' ])):
6134
6138
dr = 0.8
6135
6139
else :
@@ -6155,7 +6159,7 @@ def hist(self, x, bins=None, range=None, density=None, weights=None,
6155
6159
_barfunc = self .bar
6156
6160
bottom_kwarg = 'bottom'
6157
6161
6158
- for m , c in zip (n , color ):
6162
+ for m , c in zip (tops , color ):
6159
6163
if bottom is None :
6160
6164
bottom = np .zeros (len (m ))
6161
6165
if stacked :
@@ -6199,7 +6203,7 @@ def hist(self, x, bins=None, range=None, density=None, weights=None,
6199
6203
# For data that is normed to form a probability density,
6200
6204
# set to minimum data value / logbase
6201
6205
# (gives 1 full tick-label unit for the lowest filled bin)
6202
- ndata = np .array (n )
6206
+ ndata = np .array (tops )
6203
6207
minimum = (np .min (ndata [ndata > 0 ])) / logbase
6204
6208
else :
6205
6209
# For non-normed (density = False) data,
@@ -6222,7 +6226,7 @@ def hist(self, x, bins=None, range=None, density=None, weights=None,
6222
6226
fill = (histtype == 'stepfilled' )
6223
6227
6224
6228
xvals , yvals = [], []
6225
- for m in n :
6229
+ for m in tops :
6226
6230
if stacked :
6227
6231
# starting point for drawing polygon
6228
6232
y [0 ] = y [1 ]
@@ -6285,9 +6289,9 @@ def hist(self, x, bins=None, range=None, density=None, weights=None,
6285
6289
p .set_label ('_nolegend_' )
6286
6290
6287
6291
if nx == 1 :
6288
- return n [0 ], bins , cbook .silent_list ('Patch' , patches [0 ])
6292
+ return tops [0 ], bins , cbook .silent_list ('Patch' , patches [0 ])
6289
6293
else :
6290
- return n , bins , cbook .silent_list ('Lists of Patches' , patches )
6294
+ return tops , bins , cbook .silent_list ('Lists of Patches' , patches )
6291
6295
6292
6296
@_preprocess_data (replace_names = ["x" , "y" , "weights" ], label_namer = None )
6293
6297
def hist2d (self , x , y , bins = 10 , range = None , normed = False , weights = None ,
0 commit comments