Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 2828912

Browse files
vdbmaMarc Van den Bossche
and
Marc Van den Bossche
authored
Allow bool-like values for sharex/sharey (#24362)
Co-authored-by: Marc Van den Bossche <[email protected]>
1 parent 95762e7 commit 2828912

File tree

2 files changed

+5
-14
lines changed

2 files changed

+5
-14
lines changed

lib/matplotlib/gridspec.py

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -276,21 +276,12 @@ def subplots(self, *, sharex=False, sharey=False, squeeze=True,
276276
raise ValueError("GridSpec.subplots() only works for GridSpecs "
277277
"created with a parent figure")
278278

279-
if isinstance(sharex, bool):
279+
if not isinstance(sharex, str):
280280
sharex = "all" if sharex else "none"
281-
if isinstance(sharey, bool):
281+
if not isinstance(sharey, str):
282282
sharey = "all" if sharey else "none"
283-
# This check was added because it is very easy to type
284-
# `subplots(1, 2, 1)` when `subplot(1, 2, 1)` was intended.
285-
# In most cases, no error will ever occur, but mysterious behavior
286-
# will result because what was intended to be the subplot index is
287-
# instead treated as a bool for sharex. This check should go away
288-
# once sharex becomes kwonly.
289-
if isinstance(sharex, Integral):
290-
_api.warn_external(
291-
"sharex argument to subplots() was an integer. Did you "
292-
"intend to use subplot() (without 's')?")
293-
_api.check_in_list(["all", "row", "col", "none"],
283+
284+
_api.check_in_list(["all", "row", "col", "none", False, True],
294285
sharex=sharex, sharey=sharey)
295286
if subplot_kw is None:
296287
subplot_kw = {}

lib/matplotlib/tests/test_subplots.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ def test_shared():
8484
plt.close(f)
8585

8686
# test all option combinations
87-
ops = [False, True, 'all', 'none', 'row', 'col']
87+
ops = [False, True, 'all', 'none', 'row', 'col', 0, 1]
8888
for xo in ops:
8989
for yo in ops:
9090
f, ((a1, a2), (a3, a4)) = plt.subplots(2, 2, sharex=xo, sharey=yo)

0 commit comments

Comments
 (0)