Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Allow bool-like values for sharex/sharey #24362

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

Merged
merged 8 commits into from
Dec 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 4 additions & 13 deletions 17 lib/matplotlib/gridspec.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,21 +276,12 @@ def subplots(self, *, sharex=False, sharey=False, squeeze=True,
raise ValueError("GridSpec.subplots() only works for GridSpecs "
"created with a parent figure")

if isinstance(sharex, bool):
if not isinstance(sharex, str):
sharex = "all" if sharex else "none"
if isinstance(sharey, bool):
if not isinstance(sharey, str):
sharey = "all" if sharey else "none"
# This check was added because it is very easy to type
# `subplots(1, 2, 1)` when `subplot(1, 2, 1)` was intended.
# In most cases, no error will ever occur, but mysterious behavior
# will result because what was intended to be the subplot index is
# instead treated as a bool for sharex. This check should go away
# once sharex becomes kwonly.
if isinstance(sharex, Integral):
_api.warn_external(
"sharex argument to subplots() was an integer. Did you "
"intend to use subplot() (without 's')?")
_api.check_in_list(["all", "row", "col", "none"],

_api.check_in_list(["all", "row", "col", "none", False, True],
sharex=sharex, sharey=sharey)
if subplot_kw is None:
subplot_kw = {}
Expand Down
2 changes: 1 addition & 1 deletion 2 lib/matplotlib/tests/test_subplots.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def test_shared():
plt.close(f)

# test all option combinations
ops = [False, True, 'all', 'none', 'row', 'col']
ops = [False, True, 'all', 'none', 'row', 'col', 0, 1]
for xo in ops:
for yo in ops:
f, ((a1, a2), (a3, a4)) = plt.subplots(2, 2, sharex=xo, sharey=yo)
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.