@@ -522,19 +522,22 @@ def test_bbox():
522
522
fig , ax = plt .subplots (constrained_layout = True )
523
523
ax .set_aspect (1. )
524
524
525
+
525
526
def test_align_labels ():
526
527
"""
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
530
532
531
533
"""
532
534
533
- data = [0 ,1 ]
535
+ data = [0 , 1 ]
534
536
535
537
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 )})
538
541
539
542
ax1 .plot (data , data )
540
543
ax1 .set_ylabel ("Label" )
@@ -552,5 +555,8 @@ def test_align_labels():
552
555
after_align = (ax1 .yaxis .label .get_window_extent (),
553
556
ax2 .yaxis .label .get_window_extent (),
554
557
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