Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit ebf8853

Browse filesBrowse files
committed
Fix bugs related to bottom kwarg in step histograms
Conflicts: lib/matplotlib/axes.py lib/matplotlib/tests/baseline_images/test_axes/hist_step.png
1 parent 3d5a6bb commit ebf8853
Copy full SHA for ebf8853

File tree

Expand file treeCollapse file tree

3 files changed

+24
-8
lines changed
Filter options
Expand file treeCollapse file tree

3 files changed

+24
-8
lines changed

‎lib/matplotlib/axes.py

Copy file name to clipboardExpand all lines: lib/matplotlib/axes.py
+15-8Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8319,18 +8319,18 @@ def hist(self, x, bins=10, range=None, normed=False, weights=None,
83198319
hist_kwargs = dict(range=bin_range)
83208320

83218321
n = []
8322-
mlast = bottom
8322+
mlast = None
83238323
for i in xrange(nx):
83248324
# this will automatically overwrite bins,
83258325
# so that each histogram uses the same bins
83268326
m, bins = np.histogram(x[i], bins, weights=w[i], **hist_kwargs)
83278327
m = m.astype(float) # causes problems later if it's an int
8328-
if mlast is None:
8329-
mlast = np.zeros(len(bins)-1, m.dtype)
83308328
if normed and not stacked:
83318329
db = np.diff(bins)
83328330
m = (m.astype(float) / db) / m.sum()
83338331
if stacked:
8332+
if mlast is None:
8333+
mlast = np.zeros(len(bins)-1, m.dtype)
83348334
m += mlast
83358335
mlast[:] = m
83368336
n.append(m)
@@ -8421,6 +8421,12 @@ def hist(self, x, bins=10, range=None, normed=False, weights=None,
84218421
x[0:2*len(bins)-1:2], x[1:2*len(bins)-1:2] = bins, bins[:-1]
84228422
x[2*len(bins)-1:] = x[1:2*len(bins)-1][::-1]
84238423

8424+
if bottom is None:
8425+
bottom = np.zeros(len(bins)-1, np.float)
8426+
8427+
y[1:2*len(bins)-1:2], y[2:2*len(bins):2] = bottom, bottom
8428+
y[2*len(bins)-1:] = y[1:2*len(bins)-1][::-1]
8429+
84248430
if log:
84258431
if orientation == 'horizontal':
84268432
self.set_xscale('log', nonposx='clip')
@@ -8456,12 +8462,13 @@ def hist(self, x, bins=10, range=None, normed=False, weights=None,
84568462

84578463
xvals, yvals = [], []
84588464
for m in n:
8459-
# starting point for drawing polygon
8460-
y[0] = y[1]
8461-
# top of the previous polygon becomes the bottom
8462-
y[2*len(bins)-1:] = y[1:2*len(bins)-1][::-1]
8465+
if stacked:
8466+
# starting point for drawing polygon
8467+
y[0] = y[1]
8468+
# top of the previous polygon becomes the bottom
8469+
y[2*len(bins)-1:] = y[1:2*len(bins)-1][::-1]
84638470
# set the top of this polygon
8464-
y[1:2*len(bins)-1:2], y[2:2*len(bins)-1:2] = m, m
8471+
y[1:2*len(bins)-1:2], y[2:2*len(bins):2] = m + bottom, m + bottom
84658472
if log:
84668473
y[y < minimum] = minimum
84678474
if orientation == 'horizontal':
Loading

‎lib/matplotlib/tests/test_axes.py

Copy file name to clipboardExpand all lines: lib/matplotlib/tests/test_axes.py
+9Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1127,6 +1127,15 @@ def test_hist_stacked_normed():
11271127
ax.hist((d1, d2), stacked=True, normed=True)
11281128

11291129

1130+
@image_comparison(baseline_images=['hist_step_bottom'], extensions=['png'], remove_text=True)
1131+
def test_hist_step_bottom():
1132+
# make some data
1133+
d1 = np.linspace(1, 3, 20)
1134+
fig = plt.figure()
1135+
ax = fig.add_subplot(111)
1136+
ax.hist(d1, bottom=np.arange(10), histtype="stepfilled")
1137+
1138+
11301139
@image_comparison(baseline_images=['hist_stacked_bar'])
11311140
def test_hist_stacked_bar():
11321141
# make some data

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.