8000 Remove extra stickies in barstacked histogram. · matplotlib/matplotlib@2b5b5a9 · GitHub
[go: up one dir, main page]

Skip to content 10000

Commit 2b5b5a9

Browse files
committed
Remove extra stickies in barstacked histogram.
If we let stacked bars add their sticky edges in the middle of the bars, margin expansion can later bump into these barriers.
1 parent 2e82a38 commit 2b5b5a9

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
@@ -6660,13 +6660,19 @@ def hist(self, x, bins=None, range=None, density=False, weights=None,
66606660
height = m - bottom
66616661
else:
66626662
height = m
6663-
patch = _barfunc(bins[:-1]+boffset, height, width,
6664-
align='center', log=log,
6665-
color=c, **{bottom_kwarg: bottom})
6666-
patches.append(patch)
6663+
bars = _barfunc(bins[:-1]+boffset, height, width,
6664+
align='center', log=log,
6665+
color=c, **{bottom_kwarg: bottom})
6666+
patches.append(bars)
66676667
if stacked:
66686668
bottom[:] = m
66696669
boffset += dw
6670+
# Remove stickies from all bars but the lowest ones, as otherwise
6671+
# margin expansion would be unable to cross the stickies in the
6672+
# middle of the bars.
6673+
for bars in patches[1:]:
6674+
for patch in bars:
6675+
patch.sticky_edges.x[:] = patch.sticky_edges.y[:] = []
66706676

66716677
elif histtype.startswith('step'):
66726678
# 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)
0