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

Skip to content

Commit 9dd68a2

Browse files
author
Nora Moseman
committed
fixed formatting
1 parent 4703727 commit 9dd68a2

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

lib/matplotlib/tests/test_constrainedlayout.py

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -522,19 +522,22 @@ def test_bbox():
522522
fig, ax = plt.subplots(constrained_layout=True)
523523
ax.set_aspect(1.)
524524

525+
525526
def test_align_labels():
526527
"""
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
528+
Tests for a bug in which constrained layout and align_ylabels on
529+
three unevenly sized subplots, one of whose y tick labels include
530+
negative numbers, drives the non-negative subplots' y labels off
531+
the edge of the plot
530532
531533
"""
532534

533-
data = [0,1]
535+
data = [0, 1]
534536

535537
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+
figsize=(6.4, 8),
539+
gridspec_kw={"height_ratios": (1, 1,
540+
0.7)})
538541

539542
ax1.plot(data, data)
540543
ax1.set_ylabel("Label")
@@ -552,5 +555,8 @@ def test_align_labels():
552555
after_align = (ax1.yaxis.label.get_window_extent(),
553556
ax2.yaxis.label.get_window_extent(),
554557
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
558+
#ensure labels are approximately aligned
559+
np.testing.assert_allclose([after_align[0].x0, after_align[2].x0],
560+
after_align[1].x0, rtol=0, atol=1e-05)
561+
#ensure labels do not go off the edge
562+
assert after_align[0].x0 >= 1

0 commit comments

Comments
 (0)