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