@@ -763,7 +763,15 @@ def subplot(*args, **kwargs):
763
763
.. plot:: mpl_examples/pylab_examples/subplot_demo.py
764
764
765
765
"""
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()?" )
767
775
768
776
fig = gcf ()
769
777
a = fig .add_subplot (* args , ** kwargs )
@@ -898,6 +906,15 @@ def subplots(nrows=1, ncols=1, sharex=False, sharey=False, squeeze=True,
898
906
sharey = "none"
899
907
share_values = ["all" , "row" , "col" , "none" ]
900
908
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
+
901
918
raise ValueError ("sharex [%s] must be one of %s" % \
902
919
(sharex , share_values ))
903
920
if sharey not in share_values :
0 commit comments