Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f6dfcea

Browse files
committed
Fix bug in stacked bar histogram. Also, calling hist with log=True now
behaves correctly in all cases.
1 parent 2e1a96d commit f6dfcea

File tree

5 files changed

+1162
-240
lines changed

5 files changed

+1162
-240
lines changed

lib/matplotlib/axes.py

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4792,11 +4792,10 @@ def make_iterable(x):
47924792
if orientation == 'vertical':
47934793
self._process_unit_info(xdata=left, ydata=height, kwargs=kwargs)
47944794
if log:
4795-
self.set_yscale('log')
4795+
self.set_yscale('log', nonposy = 'clip')
47964796
# size width and bottom according to length of left
47974797
if _bottom is None:
47984798
if self.get_yscale() == 'log':
4799-
bottom = [1e-100]
48004799
adjust_ylim = True
48014800
else:
48024801
bottom = [0]
@@ -4808,11 +4807,10 @@ def make_iterable(x):
48084807
elif orientation == 'horizontal':
48094808
self._process_unit_info(xdata=width, ydata=bottom, kwargs=kwargs)
48104809
if log:
4811-
self.set_xscale('log')
4810+
self.set_xscale('log', nonposx = 'clip')
48124811
# size left and height according to length of bottom
48134812
if _left is None:
48144813
if self.get_xscale() == 'log':
4815-
left = [1e-100]
48164814
adjust_xlim = True
48174815
else:
48184816
left = [0]
@@ -8118,7 +8116,7 @@ def hist(self, x, bins=10, range=None, normed=False, weights=None,
81188116
if normed:
81198117
db = np.diff(bins)
81208118
m = (m.astype(float) / db) / m.sum()
8121-
if stacked:
8119+
if stacked :
81228120
m += mlast
81238121
mlast[:] = m
81248122
n.append(m)
@@ -8171,14 +8169,18 @@ def hist(self, x, bins=10, range=None, normed=False, weights=None,
81718169
_barfunc = self.bar
81728170

81738171
for m, c in zip(n, color):
8174-
patch = _barfunc(bins[:-1]+boffset, m, width, bottom,
8172+
if bottom is None:
8173+
bottom = np.zeros(len(m), np.float)
8174+
if stacked:
8175+
height = m-bottom
8176+
else :
8177+
height = m
8178+
patch = _barfunc(bins[:-1]+boffset, height, width, bottom,
81758179
align='center', log=log,
81768180
color=c, bottom=bottom)
81778181
patches.append(patch)
81788182
if stacked:
8179-
if bottom is None:
8180-
bottom = 0.0
8181-
bottom += m
8183+
bottom[:] = m
81828184
boffset += dw
81838185

81848186
elif histtype.startswith('step'):
@@ -8191,10 +8193,10 @@ def hist(self, x, bins=10, range=None, normed=False, weights=None,
81918193

81928194
if log:
81938195
if orientation == 'horizontal':
8194-
self.set_xscale('log')
8196+
self.set_xscale('log', nonposx = 'clip')
81958197
logbase = self.xaxis._scale.base
81968198
else: # orientation == 'vertical'
8197-
self.set_yscale('log')
8199+
self.set_yscale('log', nonposy = 'clip')
81988200
logbase = self.yaxis._scale.base
81998201

82008202
# Setting a minimum of 0 results in problems for log plots
Binary file not shown.

0 commit comments

Comments
 (0)