-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Adds row and column axes sharing to simple subplot mosaics #26327
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
878de0e
1d29bdd
48c0520
890750b
b5afe0e
da9d353
0bbb3fe
5294ebd
edfcb3f
4bf4c69
af4f6ae
4f8f73a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1234,7 +1234,8 @@ def test_nested_user_order(self): | |
assert list(ax_dict) == list("ABCDEFGHI") | ||
assert list(fig.axes) == list(ax_dict.values()) | ||
|
||
def test_share_all(self): | ||
@pytest.mark.parametrize("sharex,sharey", [(True, True), ("all", "all")]) | ||
def test_share_all(self, sharex, sharey): | ||
layout = [ | ||
["A", [["B", "C"], | ||
["D", "E"]]], | ||
|
@@ -1243,11 +1244,100 @@ def test_share_all(self): | |
["."]]]]] | ||
] | ||
fig = plt.figure() | ||
ax_dict = fig.subplot_mosaic(layout, sharex=True, sharey=True) | ||
ax_dict = fig.subplot_mosaic(layout, sharex=sharex, sharey=sharey) | ||
ax_dict["A"].set(xscale="log", yscale="logit") | ||
assert all(ax.get_xscale() == "log" and ax.get_yscale() == "logit" | ||
for ax in ax_dict.values()) | ||
|
||
@check_figures_equal(extensions=["png"]) | ||
def test_sharex_row(self, fig_test, fig_ref): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. consider doing the test similar to the Specifically, without anything actually plotted, there is no way for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Okay, I will add that. Because sharing axes affect tick labels, I'd like to keep the image comparison. |
||
fig_test.subplot_mosaic([["A", "B"], ["C", "D"]], | ||
sharex="row", sharey=False) | ||
|
||
axes_ref = fig_ref.subplot_mosaic( | ||
[ | ||
["A", "B"], | ||
["C", "D"] | ||
], | ||
sharex=False, | ||
sharey=False | ||
) | ||
axes_ref["A"].sharex(axes_ref["B"]) | ||
axes_ref["C"].sharex(axes_ref["D"]) | ||
|
||
@check_figures_equal(extensions=["png"]) | ||
def test_sharey_row(self, fig_test, fig_ref): | ||
fig_test.subplot_mosaic([["A", "B"], ["C", "D"]], | ||
sharex=False, sharey="row") | ||
|
||
axes_ref = fig_ref.subplot_mosaic( | ||
[ | ||
["A", "B"], | ||
["C", "D"] | ||
], | ||
sharex=False, | ||
sharey=False | ||
) | ||
axes_ref["A"].sharey(axes_ref["B"]) | ||
axes_ref["C"].sharey(axes_ref["D"]) | ||
axes_ref["B"].yaxis.set_tick_params(which="both", labelleft=False) | ||
axes_ref["D"].yaxis.set_tick_params(which="both", labelleft=False) | ||
|
||
@check_figures_equal(extensions=["png"]) | ||
def test_sharex_col(self, fig_test, fig_ref): | ||
fig_test.subplot_mosaic([["A", "B"], ["C", "D"]], | ||
sharex="col", sharey=False) | ||
axes_ref = fig_ref.subplot_mosaic( | ||
[ | ||
["A", "B"], | ||
["C", "D"] | ||
], | ||
sharex=False, | ||
sharey=False | ||
) | ||
axes_ref["A"].sharex(axes_ref["B"]) | ||
axes_ref["B"].sharex(axes_ref["D"]) | ||
axes_ref["A"].xaxis.set_tick_params(which="both", labelbottom=False) | ||
axes_ref["B"].xaxis.set_tick_params(which="both", labelbottom=False) | ||
|
||
@check_figures_equal(extensions=["png"]) | ||
def test_sharey_col(self, fig_test, fig_ref): | ||
fig_test.subplot_mosaic([["A", "B"], ["C", "D"]], | ||
sharex=False, sharey="col") | ||
|
||
axes_ref = fig_ref.subplot_mosaic( | ||
[ | ||
["A", "B"], | ||
["C", "D"] | ||
], | ||
sharex=False, | ||
sharey=False | ||
) | ||
axes_ref["A"].sharey(axes_ref["C"]) | ||
axes_ref["B"].sharey(axes_ref["D"]) | ||
|
||
@pytest.mark.parametrize( | ||
"sharex,sharey", | ||
[ | ||
("row", False), | ||
(False, "row"), | ||
("col", False), | ||
(False, "col"), | ||
("row", "col") | ||
] | ||
) | ||
def test_share_row_col_fails_if_nested_mosaic(self, sharex, sharey): | ||
mosaic = [ | ||
["A", [["B", "C"], | ||
["D", "E"]]], | ||
["F", "G"], | ||
[".", [["H", [["I"], | ||
["."]]]]] | ||
] | ||
fig = plt.figure() | ||
with pytest.raises(ValueError): | ||
fig.subplot_mosaic(mosaic, sharex=sharex, sharey=sharey) | ||
|
||
|
||
def test_reused_gridspec(): | ||
"""Test that these all use the same gridspec""" | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This handling was intended to to disallow "truthy" (but not
True
, the bool) and "falsy" (but notFalse
, the bool) things from giving the True/False case for sharex/ySince it is happening after normalization to string (on lines 1943-7) this is not actually doing anything here.
I think that normalization should be moved after this check.