Skip to content

Commit 4f8f73a

Browse files
committed
Add test mosaic fails if nested and share is row/col
1 parent af4f6ae commit 4f8f73a

File tree

1 file changed

+58
-11
lines changed

1 file changed

+58
-11
lines changed

lib/matplotlib/tests/test_figure.py

Lines changed: 58 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1234,7 +1234,8 @@ def test_nested_user_order(self):
12341234
assert list(ax_dict) == list("ABCDEFGHI")
12351235
assert list(fig.axes) == list(ax_dict.values())
12361236

1237-
def test_share_all(self):
1237+
@pytest.mark.parametrize("sharex,sharey", [(True, True), ("all", "all")])
1238+
def test_share_all(self, sharex, sharey):
12381239
layout = [
12391240
["A", [["B", "C"],
12401241
["D", "E"]]],
@@ -1243,7 +1244,7 @@ def test_share_all(self):
12431244
["."]]]]]
12441245
]
12451246
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)
12471248
ax_dict["A"].set(xscale="log", yscale="logit")
12481249
assert all(ax.get_xscale() == "log" and ax.get_yscale() == "logit"
12491250
for ax in ax_dict.values())
@@ -1253,8 +1254,14 @@ def test_sharex_row(self, fig_test, fig_ref):
12531254
fig_test.subplot_mosaic([["A", "B"], ["C", "D"]],
12541255
sharex="row", sharey=False)
12551256

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+
)
12581265
axes_ref["A"].sharex(axes_ref["B"])
12591266
axes_ref["C"].sharex(axes_ref["D"])
12601267

@@ -1263,8 +1270,14 @@ def test_sharey_row(self, fig_test, fig_ref):
12631270
fig_test.subplot_mosaic([["A", "B"], ["C", "D"]],
12641271
sharex=False, sharey="row")
12651272

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+
)
12681281
axes_ref["A"].sharey(axes_ref["B"])
12691282
axes_ref["C"].sharey(axes_ref["D"])
12701283
axes_ref["B"].yaxis.set_tick_params(which="both", labelleft=False)
@@ -1274,9 +1287,14 @@ def test_sharey_row(self, fig_test, fig_ref):
12741287
def test_sharex_col(self, fig_test, fig_ref):
12751288
fig_test.subplot_mosaic([["A", "B"], ["C", "D"]],
12761289
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+
)
12801298
axes_ref["A"].sharex(axes_ref["B"])
12811299
axes_ref["B"].sharex(axes_ref["D"])
12821300
axes_ref["A"].xaxis.set_tick_params(which="both", labelbottom=False)
@@ -1287,11 +1305,40 @@ def test_sharey_col(self, fig_test, fig_ref):
12871305
fig_test.subplot_mosaic([["A", "B"], ["C", "D"]],
12881306
sharex=False, sharey="col")
12891307

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+
)
12921316
axes_ref["A"].sharey(axes_ref["C"])
12931317
axes_ref["B"].sharey(axes_ref["D"])
12941318

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+
12951342
def test_reused_gridspec():
12961343
"""Test that these all use the same gridspec"""
12971344
fig = plt.figure()

0 commit comments

Comments
 (0)