@@ -813,7 +813,7 @@ def test_figure_clear(clear_meth):
813
813
assert fig .axes == []
814
814
815
815
# c) a figure multiple unnested axes
816
- axes = [fig .add_subplot (2 , 1 , i + 1 ) for i in range (2 )]
816
+ axes = [fig .add_subplot (2 , 1 , i + 1 ) for i in range (2 )]
817
817
getattr (fig , clear_meth )()
818
818
assert fig .axes == []
819
819
@@ -1287,15 +1287,21 @@ def test_subfigure():
1287
1287
1288
1288
fig .suptitle ('Figure suptitle' , fontsize = 'xx-large' )
1289
1289
1290
+ # below tests for the draw zorder of subfigures.
1291
+ leg = fig .legend (handles = [plt .Line2D ([0 ], [0 ], label = 'Line{}' .format (i ))
1292
+ for i in range (5 )], loc = 'center' )
1293
+ sub [0 ].set_zorder (leg .get_zorder () - 1 )
1294
+ sub [1 ].set_zorder (leg .get_zorder () + 1 )
1295
+
1290
1296
1291
1297
def test_subfigure_tightbbox ():
1292
1298
# test that we can get the tightbbox with a subfigure...
1293
1299
fig = plt .figure (layout = 'constrained' )
1294
1300
sub = fig .subfigures (1 , 2 )
1295
1301
1296
1302
np .testing .assert_allclose (
1297
- fig .get_tightbbox (fig .canvas .get_renderer ()).width ,
1298
- 8.0 )
1303
+ fig .get_tightbbox (fig .canvas .get_renderer ()).width ,
1304
+ 8.0 )
1299
1305
1300
1306
1301
1307
def test_subfigure_dpi ():
@@ -1386,11 +1392,11 @@ def test_subfigure_spanning():
1386
1392
1387
1393
w = 640
1388
1394
h = 480
1389
- np .testing .assert_allclose (sub_figs [0 ].bbox .min , [0. , h * 2 / 3 ])
1395
+ np .testing .assert_allclose (sub_figs [0 ].bbox .min , [0. , h * 2 / 3 ])
1390
1396
np .testing .assert_allclose (sub_figs [0 ].bbox .max , [w / 3 , h ])
1391
1397
1392
1398
np .testing .assert_allclose (sub_figs [1 ].bbox .min , [w / 3 , h / 3 ])
1393
- np .testing .assert_allclose (sub_figs [1 ].bbox .max , [w * 2 / 3 , h ])
1399
+ np .testing .assert_allclose (sub_figs [1 ].bbox .max , [w * 2 / 3 , h ])
1394
1400
1395
1401
np .testing .assert_allclose (sub_figs [2 ].bbox .min , [w / 3 , 0 ])
1396
1402
np .testing .assert_allclose (sub_figs [2 ].bbox .max , [w , h / 3 ])
@@ -1431,7 +1437,7 @@ def test_subfigure_ticks():
1431
1437
1432
1438
1433
1439
@image_comparison (['test_subfigure_scatter_size.png' ], style = 'mpl20' ,
1434
- remove_text = True )
1440
+ remove_text = True )
1435
1441
def test_subfigure_scatter_size ():
1436
1442
# markers in the left- and right-most subplots should be the same
1437
1443
fig = plt .figure ()
@@ -1458,7 +1464,7 @@ def test_subfigure_pdf():
1458
1464
1459
1465
1460
1466
def test_subfigures_wspace_hspace ():
1461
- sub_figs = plt .figure ().subfigures (2 , 3 , hspace = 0.5 , wspace = 1 / 6. )
1467
+ sub_figs = plt .figure ().subfigures (2 , 3 , hspace = 0.5 , wspace = 1 / 6. )
1462
1468
1463
1469
w = 640
1464
1470
h = 480
@@ -1482,6 +1488,26 @@ def test_subfigures_wspace_hspace():
1482
1488
np .testing .assert_allclose (sub_figs [1 , 2 ].bbox .max , [w , h * 0.4 ])
1483
1489
1484
1490
1491
+ @check_figures_equal (extensions = ["svg" , "pdf" , "eps" , "png" ])
1492
+ def test_subfigure_drawzorder (fig_test , fig_ref ):
1493
+ # this tests check that subfigures are actually drawn at the proper zorder
1494
+ line = plt .Line2D ([0 ], [0 ], label = 'Line' )
1495
+ handles = [line for i in range (9 )]
1496
+ fig_ref .set_layout_engine ('constrained' )
1497
+ fig_test .set_layout_engine ('constrained' )
1498
+
1499
+ axarr = fig_ref .subplots (2 , 2 )
1500
+ fig_ref .legend (handles = handles , loc = 'center' , ncol = 3 )
1501
+ for ax in axarr [- 1 ]:
1502
+ ax .set_zorder (10 )
1503
+
1504
+ subfigs = fig_test .subfigures (nrows = 2 , ncols = 1 )
1505
+ for subfig in subfigs :
1506
+ axarr = subfig .subplots (1 , 2 )
1507
+ subfigs [- 1 ].set_zorder (10 )
1508
+ fig_test .legend (handles = handles , loc = 'center' , ncol = 3 )
1509
+
1510
+
1485
1511
def test_add_subplot_kwargs ():
1486
1512
# fig.add_subplot() always creates new axes, even if axes kwargs differ.
1487
1513
fig = plt .figure ()
@@ -1614,7 +1640,7 @@ def test_deepcopy():
1614
1640
def test_unpickle_with_device_pixel_ratio ():
1615
1641
fig = Figure (dpi = 42 )
1616
1642
fig .canvas ._set_device_pixel_ratio (7 )
1617
- assert fig .dpi == 42 * 7
1643
+ assert fig .dpi == 42 * 7
1618
1644
fig2 = pickle .loads (pickle .dumps (fig ))
1619
1645
assert fig2 .dpi == 42
1620
1646
0 commit comments