@@ -1230,10 +1230,18 @@ def add_patch(self, p):
12301230
12311231 def _update_patch_limits (self , p ):
12321232 '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+
12331240 vertices = p .get_patch_transform ().transform (p .get_path ().vertices )
12341241 if p .get_data_transform () != self .transData :
12351242 transform = p .get_data_transform () + self .transData .inverted ()
12361243 xys = transform .transform (vertices )
1244+
12371245 self .update_datalim (vertices )
12381246
12391247 def add_table (self , tab ):
@@ -3509,14 +3517,15 @@ def make_iterable(x):
35093517
35103518 if adjust_xlim :
35113519 xmin , xmax = self .dataLim .intervalx
3512- xmin = np .amin (width )
3520+ xmin = np .amin (width [ width != 0 ]) # filter out the 0 width rects
35133521 if xerr is not None :
35143522 xmin = xmin - np .amax (xerr )
35153523 xmin = max (xmin * 0.9 , 1e-100 )
35163524 self .dataLim .intervalx = (xmin , xmax )
3525+
35173526 if adjust_ylim :
35183527 ymin , ymax = self .dataLim .intervaly
3519- ymin = np .amin (height )
3528+ ymin = np .amin (height [ height != 0 ]) # filter out the 0 height rects
35203529 if yerr is not None :
35213530 ymin = ymin - np .amax (yerr )
35223531 ymin = max (ymin * 0.9 , 1e-100 )
@@ -5501,7 +5510,10 @@ def hist(self, x, bins=10, normed=False, cumulative=False,
55015510 width. If None, automatically compute the width. Ignored
55025511 for 'step' histtype.
55035512
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.
55055517
55065518 kwargs are used to update the properties of the
55075519 hist Rectangles:
@@ -5587,6 +5599,7 @@ def hist(self, x, bins=10, normed=False, cumulative=False,
55875599 ccount += 1
55885600 elif orientation == 'vertical' :
55895601 for m in n :
5602+
55905603 color = colors [ccount % len (colors )]
55915604 patch = self .bar (bins [:- 1 ]+ boffset , m , width = width ,
55925605 bottom = bottom , align = 'center' , log = log ,
0 commit comments