@@ -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,12 +906,20 @@ 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 an integer."
916+ " Did you intend to use subplot() (without 's')?" )
917+
901918 raise ValueError ("sharex [%s] must be one of %s" % \
902919 (sharex , share_values ))
903920 if sharey not in share_values :
904921 raise ValueError ("sharey [%s] must be one of %s" % \
905922 (sharey , share_values ))
906-
907923 if subplot_kw is None :
908924 subplot_kw = {}
909925
0 commit comments