@@ -1234,7 +1234,8 @@ def test_nested_user_order(self):
1234
1234
assert list (ax_dict ) == list ("ABCDEFGHI" )
1235
1235
assert list (fig .axes ) == list (ax_dict .values ())
1236
1236
1237
- def test_share_all (self ):
1237
+ @pytest .mark .parametrize ("sharex,sharey" , [(True , True ), ("all" , "all" )])
1238
+ def test_share_all (self , sharex , sharey ):
1238
1239
layout = [
1239
1240
["A" , [["B" , "C" ],
1240
1241
["D" , "E" ]]],
@@ -1243,7 +1244,7 @@ def test_share_all(self):
1243
1244
["." ]]]]]
1244
1245
]
1245
1246
fig = plt .figure ()
1246
- ax_dict = fig .subplot_mosaic (layout , sharex = True , sharey = True )
1247
+ ax_dict = fig .subplot_mosaic (layout , sharex = sharex , sharey = sharey )
1247
1248
ax_dict ["A" ].set (xscale = "log" , yscale = "logit" )
1248
1249
assert all (ax .get_xscale () == "log" and ax .get_yscale () == "logit"
1249
1250
for ax in ax_dict .values ())
@@ -1253,8 +1254,14 @@ def test_sharex_row(self, fig_test, fig_ref):
1253
1254
fig_test .subplot_mosaic ([["A" , "B" ], ["C" , "D" ]],
1254
1255
sharex = "row" , sharey = False )
1255
1256
1256
- axes_ref = fig_ref .subplot_mosaic ([["A" , "B" ], ["C" , "D" ]],
1257
- sharex = False , sharey = False )
1257
+ axes_ref = fig_ref .subplot_mosaic (
1258
+ [
1259
+ ["A" , "B" ],
1260
+ ["C" , "D" ]
1261
+ ],
1262
+ sharex = False ,
1263
+ sharey = False
1264
+ )
1258
1265
axes_ref ["A" ].sharex (axes_ref ["B" ])
1259
1266
axes_ref ["C" ].sharex (axes_ref ["D" ])
1260
1267
@@ -1263,8 +1270,14 @@ def test_sharey_row(self, fig_test, fig_ref):
1263
1270
fig_test .subplot_mosaic ([["A" , "B" ], ["C" , "D" ]],
1264
1271
sharex = False , sharey = "row" )
1265
1272
1266
- axes_ref = fig_ref .subplot_mosaic ([["A" , "B" ], ["C" , "D" ]],
1267
- sharex = False , sharey = False )
1273
+ axes_ref = fig_ref .subplot_mosaic (
1274
+ [
1275
+ ["A" , "B" ],
1276
+ ["C" , "D" ]
1277
+ ],
1278
+ sharex = False ,
1279
+ sharey = False
1280
+ )
1268
1281
axes_ref ["A" ].sharey (axes_ref ["B" ])
1269
1282
axes_ref ["C" ].sharey (axes_ref ["D" ])
1270
1283
axes_ref ["B" ].yaxis .set_tick_params (which = "both" , labelleft = False )
@@ -1274,9 +1287,14 @@ def test_sharey_row(self, fig_test, fig_ref):
1274
1287
def test_sharex_col (self , fig_test , fig_ref ):
1275
1288
fig_test .subplot_mosaic ([["A" , "B" ], ["C" , "D" ]],
1276
1289
sharex = "col" , sharey = False )
1277
-
1278
- axes_ref = fig_ref .subplot_mosaic ([["A" , "B" ], ["C" , "D" ]],
1279
- sharex = False , sharey = False )
1290
+ axes_ref = fig_ref .subplot_mosaic (
1291
+ [
1292
+ ["A" , "B" ],
1293
+ ["C" , "D" ]
1294
+ ],
1295
+ sharex = False ,
1296
+ sharey = False
1297
+ )
1280
1298
axes_ref ["A" ].sharex (axes_ref ["B" ])
1281
1299
axes_ref ["B" ].sharex (axes_ref ["D" ])
1282
1300
axes_ref ["A" ].xaxis .set_tick_params (which = "both" , labelbottom = False )
@@ -1287,11 +1305,40 @@ def test_sharey_col(self, fig_test, fig_ref):
1287
1305
fig_test .subplot_mosaic ([["A" , "B" ], ["C" , "D" ]],
1288
1306
sharex = False , sharey = "col" )
1289
1307
1290
- axes_ref = fig_ref .subplot_mosaic ([["A" , "B" ], ["C" , "D" ]],
1291
- sharex = False , sharey = False )
1308
+ axes_ref = fig_ref .subplot_mosaic (
1309
+ [
1310
+ ["A" , "B" ],
1311
+ ["C" , "D" ]
1312
+ ],
1313
+ sharex = False ,
1314
+ sharey = False
1315
+ )
1292
1316
axes_ref ["A" ].sharey (axes_ref ["C" ])
1293
1317
axes_ref ["B" ].sharey (axes_ref ["D" ])
1294
1318
1319
+ @pytest .mark .parametrize (
1320
+ "sharex,sharey" ,
1321
+ [
1322
+ ("row" , False ),
1323
+ (False , "row" ),
1324
+ ("col" , False ),
1325
+ (False , "col" ),
1326
+ ("row" , "col" )
1327
+ ]
1328
+ )
1329
+ def test_share_row_col_fails_if_nested_mosaic (self , sharex , sharey ):
1330
+ mosaic = [
1331
+ ["A" , [["B" , "C" ],
1332
+ ["D" , "E" ]]],
1333
+ ["F" , "G" ],
1334
+ ["." , [["H" , [["I" ],
1335
+ ["." ]]]]]
1336
+ ]
1337
+ fig = plt .figure ()
1338
+ with pytest .raises (ValueError ):
1339
+ fig .subplot_mosaic (mosaic , sharex = sharex , sharey = sharey )
1340
+
1341
+
1295
1342
def test_reused_gridspec ():
1296
1343
"""Test that these all use the same gridspec"""
1297
1344
fig = plt .figure ()
0 commit comments