@@ -6656,36 +6656,28 @@ def hist(self, x, bins=None, range=None, density=None, weights=None,
6656
6656
hist_kwargs = dict (range = bin_range )
6657
6657
6658
6658
# List to store all the top coordinates of the histograms
6659
- tops = []
6660
- mlast = None
6659
+ tops = [] # Will have shape (n_datasets, n_bins).
6661
6660
# Loop through datasets
6662
6661
for i in range (nx ):
6663
6662
# this will automatically overwrite bins,
6664
6663
# so that each histogram uses the same bins
6665
6664
m , bins = np .histogram (x [i ], bins , weights = w [i ], ** hist_kwargs )
6666
- m = m .astype (float ) # causes problems later if it's an int
6667
- if mlast is None :
6668
- mlast = np .zeros (len (bins )- 1 , m .dtype )
6669
- if stacked :
6670
- m += mlast
6671
- mlast [:] = m
6672
6665
tops .append (m )
6673
-
6674
- # If a stacked density plot, normalize so the area of all the stacked
6675
- # histograms together is 1
6676
- if stacked and density :
6677
- db = np . diff ( bins )
6678
- for m in tops :
6679
- m [:] = (m / db ) / tops [- 1 ].sum ()
6666
+ tops = np . array ( tops , float ) # causes problems later if it's an int
6667
+ if stacked :
6668
+ tops = tops . cumsum ( axis = 0 )
6669
+ # If a stacked density plot, normalize so the area of all the
6670
+ # stacked histograms together is 1
6671
+ if density :
6672
+ tops = (tops / np . diff ( bins ) ) / tops [- 1 ].sum ()
6680
6673
if cumulative :
6681
6674
slc = slice (None )
6682
6675
if isinstance (cumulative , Number ) and cumulative < 0 :
6683
6676
slc = slice (None , None , - 1 )
6684
-
6685
6677
if density :
6686
- tops = [( m * np .diff (bins ))[slc ].cumsum ()[ slc ] for m in tops ]
6678
+ tops = ( tops * np .diff (bins ))[:, slc ].cumsum (axis = 1 )[:, slc ]
6687
6679
else :
6688
- tops = [ m [ slc ].cumsum ()[ slc ] for m in tops ]
6680
+ tops = tops [:, slc ].cumsum (axis = 1 )[:, slc ]
6689
6681
6690
6682
patches = []
6691
6683
0 commit comments