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

Skip to content

Commit 687fd12

Browse files
authored
Merge pull request #18465 from anntzer/histstackedbottom
Don't modify bottom argument in place in stacked histograms.
2 parents e146733 + b1c3b34 commit 687fd12

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

lib/matplotlib/axes/_axes.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6665,7 +6665,7 @@ def hist(self, x, bins=None, range=None, density=False, weights=None,
66656665
color=c, **{bottom_kwarg: bottom})
66666666
patches.append(patch)
66676667
if stacked:
6668-
bottom[:] = m
6668+
bottom = m
66696669
boffset += dw
66706670

66716671
elif histtype.startswith('step'):

lib/matplotlib/tests/test_axes.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3532,6 +3532,12 @@ def test_hist_stacked_bar():
35323532
ax.legend(loc='upper right', bbox_to_anchor=(1.0, 1.0), ncol=1)
35333533

35343534

3535+
def test_hist_barstacked_bottom_unchanged():
3536+
b = np.array([10, 20])
3537+
plt.hist([[0, 1], [0, 1]], 2, histtype="barstacked", bottom=b)
3538+
assert b.tolist() == [10, 20]
3539+
3540+
35353541
def test_hist_emptydata():
35363542
fig = plt.figure()
35373543
ax = fig.add_subplot(111)

0 commit comments

Comments
 (0)