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

Skip to content

Commit 0b1eb01

Browse files
authored
Merge pull request #18469 from meeseeksmachine/auto-backport-of-pr-18464-on-v3.3.x
Backport PR #18464 on branch v3.3.x (Remove extra stickies in barstacked histogram.)
2 parents 9a54497 + fc0b96d commit 0b1eb01

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

lib/matplotlib/axes/_axes.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6712,13 +6712,19 @@ def hist(self, x, bins=None, range=None, density=False, weights=None,
67126712
height = m - bottom
67136713
else:
67146714
height = m
6715-
patch = _barfunc(bins[:-1]+boffset, height, width,
6716-
align='center', log=log,
6717-
color=c, **{bottom_kwarg: bottom})
6718-
patches.append(patch)
6715+
bars = _barfunc(bins[:-1]+boffset, height, width,
6716+
align='center', log=log,
6717+
color=c, **{bottom_kwarg: bottom})
6718+
patches.append(bars)
67196719
if stacked:
67206720
bottom[:] = m
67216721
boffset += dw
6722+
# Remove stickies from all bars but the lowest ones, as otherwise
6723+
# margin expansion would be unable to cross the stickies in the
6724+
# middle of the bars.
6725+
for bars in patches[1:]:
6726+
for patch in bars:
6727+
patch.sticky_edges.x[:] = patch.sticky_edges.y[:] = []
67226728

67236729
elif histtype.startswith('step'):
67246730
# these define the perimeter of the polygon

lib/matplotlib/tests/test_axes.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1651,6 +1651,16 @@ def test_hist_log_2(fig_test, fig_ref):
16511651
ax.hist(1, 1, log=True, histtype=histtype)
16521652

16531653

1654+
def test_hist_log_barstacked():
1655+
fig, axs = plt.subplots(2)
1656+
axs[0].hist([[0], [0, 1]], 2, histtype="barstacked")
1657+
axs[0].set_yscale("log")
1658+
axs[1].hist([0, 0, 1], 2, histtype="barstacked")
1659+
axs[1].set_yscale("log")
1660+
fig.canvas.draw()
1661+
assert axs[0].get_ylim() == axs[1].get_ylim()
1662+
1663+
16541664
@image_comparison(['hist_bar_empty.png'], remove_text=True)
16551665
def test_hist_bar_empty():
16561666
# From #3886: creating hist from empty dataset raises ValueError

0 commit comments

Comments
 (0)