FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Allow bool-like values for sharex/sharey by vdbma · Pull Request #24362 · matplotlib/matplotlib · GitHub

Repository navigation

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .py  (2) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
17 changes: 4 additions & 13 deletions lib/matplotlib/gridspec.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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 lib/matplotlib/tests/test_subplots.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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

Back | FazBrowse Home | New Git URL