@@ -7396,9 +7396,21 @@ def hist(self, x, bins=10, range=None, normed=False, weights=None,
7396
7396
w = [None ]* nx
7397
7397
7398
7398
# Check whether bins or range are given explicitly. In that
7399
- # case do not autoscale axes .
7399
+ # case use those values for autoscaling .
7400
7400
binsgiven = (cbook .iterable (bins ) or range != None )
7401
7401
7402
+ # Save autoscale state for later restoration; turn autoscaling
7403
+ # off so we can do it all a single time at the end, instead
7404
+ # of having it done by bar or fill and then having to be redone.
7405
+ _saved_autoscalex = self .get_autoscalex_on ()
7406
+ _saved_autoscaley = self .get_autoscaley_on ()
7407
+ self .set_autoscalex_on (False )
7408
+ self .set_autoscaley_on (False )
7409
+
7410
+ # Save the datalimits for the same reason:
7411
+ _saved_bounds = self .dataLim .bounds
7412
+
7413
+
7402
7414
hist_kwargs = dict (range = range , normed = bool (normed ))
7403
7415
if np .__version__ < "1.3" : # version 1.1 and 1.2
7404
7416
hist_kwargs ['new' ] = True
@@ -7503,18 +7515,21 @@ def hist(self, x, bins=10, range=None, normed=False, weights=None,
7503
7515
7504
7516
# adopted from adjust_x/ylim part of the bar method
7505
7517
if orientation == 'horizontal' :
7506
- xmin , xmax = 0 , self .dataLim .intervalx [1 ]
7518
+ xmin0 = max (_saved_bounds [0 ]* 0.9 , 1e-100 )
7519
+ xmax = self .dataLim .intervalx [1 ]
7507
7520
for m in n :
7508
7521
xmin = np .amin (m [m != 0 ]) # filter out the 0 height bins
7509
7522
xmin = max (xmin * 0.9 , 1e-100 )
7523
+ xmin = min (xmin0 , xmin )
7510
7524
self .dataLim .intervalx = (xmin , xmax )
7511
7525
elif orientation == 'vertical' :
7512
- ymin , ymax = 0 , self .dataLim .intervaly [1 ]
7526
+ ymin0 = max (_saved_bounds [1 ]* 0.9 , 1e-100 )
7527
+ ymax = self .dataLim .intervaly [1 ]
7513
7528
for m in n :
7514
7529
ymin = np .amin (m [m != 0 ]) # filter out the 0 height bins
7515
7530
ymin = max (ymin * 0.9 , 1e-100 )
7531
+ ymin = min (ymin0 , ymin )
7516
7532
self .dataLim .intervaly = (ymin , ymax )
7517
- self .autoscale_view ()
7518
7533
7519
7534
if label is None :
7520
7535
labels = ['_nolegend_' ]
@@ -7535,17 +7550,14 @@ def hist(self, x, bins=10, range=None, normed=False, weights=None,
7535
7550
lbl = '_nolegend_'
7536
7551
7537
7552
if binsgiven :
7538
- self .set_autoscale_on (False )
7539
7553
if orientation == 'vertical' :
7540
- self .autoscale_view (scalex = False , scaley = True )
7541
- XL = self .xaxis .get_major_locator ().view_limits (
7542
- bins [0 ], bins [- 1 ])
7543
- self .set_xbound (XL )
7554
+ self .update_datalim ([(bins [0 ],0 ), (bins [- 1 ],0 )], updatey = False )
7544
7555
else :
7545
- self .autoscale_view (scalex = True , scaley = False )
7546
- YL = self .yaxis .get_major_locator ().view_limits (
7547
- bins [0 ], bins [- 1 ])
7548
- self .set_ybound (YL )
7556
+ self .update_datalim ([(0 ,bins [0 ]), (0 ,bins [- 1 ])], updatex = False )
7557
+
7558
+ self .set_autoscalex_on (_saved_autoscalex )
7559
+ self .set_autoscaley_on (_saved_autoscaley )
7560
+ self .autoscale_view ()
7549
7561
7550
7562
if nx == 1 :
7551
7563
return n [0 ], bins , cbook .silent_list ('Patch' , patches [0 ])
0 commit comments