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

Skip to content

Commit cab4f02

Browse files
authored
Merge pull request #18464 from anntzer/barstackedsticky
Remove extra stickies in barstacked histogram.
2 parents 15b71b3 + 2b5b5a9 commit cab4f02

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
@@ -6652,13 +6652,19 @@ def hist(self, x, bins=None, range=None, density=False, weights=None,
66526652
height = m - bottom
66536653
else:
66546654
height = m
6655-
patch = _barfunc(bins[:-1]+boffset, height, width,
6656-
align='center', log=log,
6657-
color=c, **{bottom_kwarg: bottom})
6658-
patches.append(patch)
6655+
bars = _barfunc(bins[:-1]+boffset, height, width,
6656+
align='center', log=log,
6657+
color=c, **{bottom_kwarg: bottom})
6658+
patches.append(bars)
66596659
if stacked:
66606660
bottom = m
66616661
boffset += dw
6662+
# Remove stickies from all bars but the lowest ones, as otherwise
6663+
# margin expansion would be unable to cross the stickies in the
6664+
# middle of the bars.
6665+
for bars in patches[1:]:
6666+
for patch in bars:
6667+
patch.sticky_edges.x[:] = patch.sticky_edges.y[:] = []
66626668

66636669
elif histtype.startswith('step'):
66646670
# 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
@@ -1679,6 +1679,16 @@ def test_hist_log_2(fig_test, fig_ref):
16791679
ax.hist(1, 1, log=True, histtype=histtype)
16801680

16811681

1682+
def test_hist_log_barstacked():
1683+
fig, axs = plt.subplots(2)
1684+
axs[0].hist([[0], [0, 1]], 2, histtype="barstacked")
1685+
axs[0].set_yscale("log")
1686+
axs[1].hist([0, 0, 1], 2, histtype="barstacked")
1687+
axs[1].set_yscale("log")
1688+
fig.canvas.draw()
1689+
assert axs[0].get_ylim() == axs[1].get_ylim()
1690+
1691+
16821692
@image_comparison(['hist_bar_empty.png'], remove_text=True)
16831693
def test_hist_bar_empty():
16841694
# From #3886: creating hist from empty dataset raises ValueError

0 commit comments

Comments
 (0)