@@ -1230,10 +1230,18 @@ def add_patch(self, p):
1230
1230
1231
1231
def _update_patch_limits (self , p ):
1232
1232
'update the datalimits for patch p'
1233
+ # hist can add zero height Rectangles, which is useful to keep
1234
+ # the bins, counts and patches lined up, but it throws off log
1235
+ # scaling. We'll ignore rects with zero height or width in
1236
+ # the auto-scaling
1237
+ if isinstance (p , mpatches .Rectangle ) and p .get_width ()== 0. or p .get_height ()== 0. :
1238
+ return
1239
+
1233
1240
vertices = p .get_patch_transform ().transform (p .get_path ().vertices )
1234
1241
if p .get_data_transform () != self .transData :
1235
1242
transform = p .get_data_transform () + self .transData .inverted ()
1236
1243
xys = transform .transform (vertices )
1244
+
1237
1245
self .update_datalim (vertices )
1238
1246
1239
1247
def add_table (self , tab ):
@@ -3509,14 +3517,15 @@ def make_iterable(x):
3509
3517
3510
3518
if adjust_xlim :
3511
3519
xmin , xmax = self .dataLim .intervalx
3512
- xmin = np .amin (width )
3520
+ xmin = np .amin (width [ width != 0 ]) # filter out the 0 width rects
3513
3521
if xerr is not None :
3514
3522
xmin = xmin - np .amax (xerr )
3515
3523
xmin = max (xmin * 0.9 , 1e-100 )
3516
3524
self .dataLim .intervalx = (xmin , xmax )
3525
+
3517
3526
if adjust_ylim :
3518
3527
ymin , ymax = self .dataLim .intervaly
3519
- ymin = np .amin (height )
3528
+ ymin = np .amin (height [ height != 0 ]) # filter out the 0 height rects
3520
3529
if yerr is not None :
3521
3530
ymin = ymin - np .amax (yerr )
3522
3531
ymin = max (ymin * 0.9 , 1e-100 )
@@ -5501,7 +5510,10 @@ def hist(self, x, bins=10, normed=False, cumulative=False,
5501
5510
width. If None, automatically compute the width. Ignored
5502
5511
for 'step' histtype.
5503
5512
5504
- log: if True, the histogram axis will be set to a log scale
5513
+ log: if True, the histogram axis will be set to a log scale.
5514
+ If log is true and x is a 1D array, empty bins will be
5515
+ filtered out and only the non-empty n, bins, patches will be
5516
+ returned.
5505
5517
5506
5518
kwargs are used to update the properties of the
5507
5519
hist Rectangles:
@@ -5587,6 +5599,7 @@ def hist(self, x, bins=10, normed=False, cumulative=False,
5587
5599
ccount += 1
5588
5600
elif orientation == 'vertical' :
5589
5601
for m in n :
5602
+
5590
5603
color = colors [ccount % len (colors )]
5591
5604
patch = self .bar (bins [:- 1 ]+ boffset , m , width = width ,
5592
5605
bottom = bottom , align = 'center' , log = log ,
0 commit comments