Skip to content

Commit 64130e2

Browse files
committed
Merging the changes to subplots() with my warnings code
1 parent 5b90a27 commit 64130e2

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

lib/matplotlib/pyplot.py

+18-1
Original file line numberDiff line numberDiff line change
@@ -763,7 +763,15 @@ def subplot(*args, **kwargs):
763763
.. plot:: mpl_examples/pylab_examples/subplot_demo.py
764764
765765
"""
766-
766+
# This check was added because it is very easy to type
767+
# subplot(1, 2, False) when subplots(1, 2, False) was intended
768+
# (sharex=False, that is). In most cases, no error will
769+
# ever occur, but mysterious behavior can result because what was
770+
# intended to be the sharex argument is instead treated as a
771+
# subplot index for subplot()
772+
if len(args) >= 3 and isinstance(args[2], bool) :
773+
warnings.warn("The subplot index argument to subplot() appears"
774+
" to be a boolean. Did you intend to use subplots()?")
767775

768776
fig = gcf()
769777
a = fig.add_subplot(*args, **kwargs)
@@ -898,6 +906,15 @@ def subplots(nrows=1, ncols=1, sharex=False, sharey=False, squeeze=True,
898906
sharey = "none"
899907
share_values = ["all", "row", "col", "none"]
900908
if sharex not in share_values:
909+
# This check was added because it is very easy to type subplots(1, 2, 1)
910+
# when subplot(1, 2, 1) was intended. In most cases, no error will
911+
# ever occur, but mysterious behavior will result because what was
912+
# intended to be the subplot index is instead treated as a bool for
913+
# sharex.
914+
if isinstance(sharex, int) :
915+
warnings.warn("sharex argument to subplots() was not boolean."
916+
" Did you intend to use subplot()?")
917+
901918
raise ValueError("sharex [%s] must be one of %s" % \
902919
(sharex, share_values))
903920
if sharey not in share_values:

0 commit comments

Comments
 (0)