Skip to content

Commit 3235ed8

Browse files
author
Nora Moseman
committed
test for align_ylabel constrained_layout bug: first implementation
1 parent 46a4e85 commit 3235ed8

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

lib/matplotlib/tests/test_constrainedlayout.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -521,3 +521,36 @@ def test_bboxtight():
521521
def test_bbox():
522522
fig, ax = plt.subplots(constrained_layout=True)
523523
ax.set_aspect(1.)
524+
525+
def test_align_labels():
526+
"""
527+
Tests for a bug in which constrained layout and align_ylabels on three
528+
unevenly sized subplots, one of whose y tick labels include negative
529+
numbers, drives the non-negative subplots' y labels off the edge of the plot
530+
531+
"""
532+
533+
data = [0,1]
534+
535+
fig, (ax3, ax1, ax2) = plt.subplots(3, 1, constrained_layout=True,
536+
figsize=(6.4,8),
537+
gridspec_kw={"height_ratios":(1, 1, 0.7)})
538+
539+
ax1.plot(data, data)
540+
ax1.set_ylabel("Label")
541+
542+
ax2.plot(data, data)
543+
ax2.set_ylim(-1.5, 1.5)
544+
ax2.set_ylabel("Label")
545+
546+
ax3.plot(data, data)
547+
ax3.set_ylabel("Label")
548+
549+
fig.align_ylabels(axs=(ax3, ax1, ax2))
550+
551+
fig.canvas.draw()
552+
after_align = (ax1.yaxis.label.get_window_extent(),
553+
ax2.yaxis.label.get_window_extent(),
554+
ax3.yaxis.label.get_window_extent())
555+
556+
assert round(after_align[0].x0, 5) == round(after_align[1].x0, 5) == round(after_align[2].x0, 5) > 1

0 commit comments

Comments
 (0)