@@ -6110,13 +6110,6 @@ def hist(self, x, bins=None, range=None, density=None, weights=None,
6110
6110
--------
6111
6111
hist2d : 2D histograms
6112
6112
6113
- Notes
6114
- -----
6115
- Until numpy release 1.5, the underlying numpy histogram function was
6116
- incorrect with ``normed=True`` if bin sizes were unequal. MPL
6117
- inherited that error. It is now corrected within MPL when using
6118
- earlier numpy versions.
6119
-
6120
6113
"""
6121
6114
# Avoid shadowing the builtin.
6122
6115
bin_range = range
@@ -6209,38 +6202,37 @@ def hist(self, x, bins=None, range=None, density=None, weights=None,
6209
6202
else :
6210
6203
hist_kwargs = dict (range = bin_range )
6211
6204
6212
- n = []
6205
+ # List to store all the top coordinates of the histograms
6206
+ tops = []
6213
6207
mlast = None
6208
+ # Loop through datasets
6214
6209
for i in xrange (nx ):
6215
6210
# this will automatically overwrite bins,
6216
6211
# so that each histogram uses the same bins
6217
6212
m , bins = np .histogram (x [i ], bins , weights = w [i ], ** hist_kwargs )
6218
6213
m = m .astype (float ) # causes problems later if it's an int
6219
6214
if mlast is None :
6220
6215
mlast = np .zeros (len (bins )- 1 , m .dtype )
6221
- if density and not stacked :
6222
- db = np .diff (bins )
6223
- m = (m .astype (float ) / db ) / m .sum ()
6224
6216
if stacked :
6225
- if mlast is None :
6226
- mlast = np .zeros (len (bins )- 1 , m .dtype )
6227
6217
m += mlast
6228
6218
mlast [:] = m
6229
- n .append (m )
6219
+ tops .append (m )
6230
6220
6221
+ # If a stacked density plot, normalize so the area of all the stacked
6222
+ # histograms together is 1
6231
6223
if stacked and density :
6232
6224
db = np .diff (bins )
6233
- for m in n :
6234
- m [:] = (m .astype (float ) / db ) / n [- 1 ].sum ()
6225
+ for m in tops :
6226
+ m [:] = (m .astype (float ) / db ) / tops [- 1 ].sum ()
6235
6227
if cumulative :
6236
6228
slc = slice (None )
6237
6229
if cbook .is_numlike (cumulative ) and cumulative < 0 :
6238
6230
slc = slice (None , None , - 1 )
6239
6231
6240
6232
if density :
6241
- n = [(m * np .diff (bins ))[slc ].cumsum ()[slc ] for m in n ]
6233
+ tops = [(m * np .diff (bins ))[slc ].cumsum ()[slc ] for m in tops ]
6242
6234
else :
6243
- n = [m [slc ].cumsum ()[slc ] for m in n ]
6235
+ tops = [m [slc ].cumsum ()[slc ] for m in tops ]
6244
6236
6245
6237
patches = []
6246
6238
@@ -6258,7 +6250,7 @@ def hist(self, x, bins=None, range=None, density=None, weights=None,
6258
6250
6259
6251
if rwidth is not None :
6260
6252
dr = np .clip (rwidth , 0 , 1 )
6261
- elif (len (n ) > 1 and
6253
+ elif (len (tops ) > 1 and
6262
6254
((not stacked ) or rcParams ['_internal.classic_mode' ])):
6263
6255
dr = 0.8
6264
6256
else :
@@ -6284,7 +6276,7 @@ def hist(self, x, bins=None, range=None, density=None, weights=None,
6284
6276
_barfunc = self .bar
6285
6277
bottom_kwarg = 'bottom'
6286
6278
6287
- for m , c in zip (n , color ):
6279
+ for m , c in zip (tops , color ):
6288
6280
if bottom is None :
6289
6281
bottom = np .zeros (len (m ))
6290
6282
if stacked :
@@ -6328,7 +6320,7 @@ def hist(self, x, bins=None, range=None, density=None, weights=None,
6328
6320
# For data that is normed to form a probability density,
6329
6321
# set to minimum data value / logbase
6330
6322
# (gives 1 full tick-label unit for the lowest filled bin)
6331
- ndata = np .array (n )
6323
+ ndata = np .array (tops )
6332
6324
minimum = (np .min (ndata [ndata > 0 ])) / logbase
6333
6325
else :
6334
6326
# For non-normed (density = False) data,
@@ -6351,7 +6343,7 @@ def hist(self, x, bins=None, range=None, density=None, weights=None,
6351
6343
fill = (histtype == 'stepfilled' )
6352
6344
6353
6345
xvals , yvals = [], []
6354
- for m in n :
6346
+ for m in tops :
6355
6347
if stacked :
6356
6348
# starting point for drawing polygon
6357
6349
y [0 ] = y [1 ]
@@ -6414,9 +6406,9 @@ def hist(self, x, bins=None, range=None, density=None, weights=None,
6414
6406
p .set_label ('_nolegend_' )
6415
6407
6416
6408
if nx == 1 :
6417
- return n [0 ], bins , cbook .silent_list ('Patch' , patches [0 ])
6409
+ return tops [0 ], bins , cbook .silent_list ('Patch' , patches [0 ])
6418
6410
else :
6419
- return n , bins , cbook .silent_list ('Lists of Patches' , patches )
6411
+ return tops , bins , cbook .silent_list ('Lists of Patches' , patches )
6420
6412
6421
6413
@_preprocess_data (replace_names = ["x" , "y" , "weights" ], label_namer = None )
6422
6414
def hist2d (self , x , y , bins = 10 , range = None , normed = False , weights = None ,
0 commit comments