Skip to content

Commit f24d06c

Browse files
committed
zero area rects no longer influence auto-scaling
svn path=/trunk/matplotlib/; revision=5285
1 parent 3061f58 commit f24d06c

File tree

3 files changed

+21
-3
lines changed

3 files changed

+21
-3
lines changed

API_CHANGES

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
12
Rewrote the cm.ScalarMappable callback infrastructure to use
23
cbook.CallbackRegistry rather than custom callback handling. Amy
34
users of add_observer/notify of the cm.ScalarMappable should uae

CHANGELOG

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
2008-05-28 zero width/height Rectangles no longer influence the
2+
autoscaler. Useful for log histograms with empty bins -
3+
JDH
4+
15
2008-05-28 Fix rendering of composite glyphs in Type 3 conversion
26
(particularly as evidenced in the Eunjin.ttf Korean font)
37
Thanks Jae-Joon Lee for finding this!

lib/matplotlib/axes.py

+16-3
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)