From 64130e20838a59131ea6e74e29a2a07c053333d8 Mon Sep 17 00:00:00 2001 From: Benjamin Root Date: Thu, 5 Jul 2012 23:30:31 -0400 Subject: [PATCH 1/2] Merging the changes to subplots() with my warnings code --- lib/matplotlib/pyplot.py | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/lib/matplotlib/pyplot.py b/lib/matplotlib/pyplot.py index 229355bab969..d169d392201d 100644 --- a/lib/matplotlib/pyplot.py +++ b/lib/matplotlib/pyplot.py @@ -763,7 +763,15 @@ def subplot(*args, **kwargs): .. plot:: mpl_examples/pylab_examples/subplot_demo.py """ - + # This check was added because it is very easy to type + # subplot(1, 2, False) when subplots(1, 2, False) was intended + # (sharex=False, that is). In most cases, no error will + # ever occur, but mysterious behavior can result because what was + # intended to be the sharex argument is instead treated as a + # subplot index for subplot() + if len(args) >= 3 and isinstance(args[2], bool) : + warnings.warn("The subplot index argument to subplot() appears" + " to be a boolean. Did you intend to use subplots()?") fig = gcf() a = fig.add_subplot(*args, **kwargs) @@ -898,6 +906,15 @@ def subplots(nrows=1, ncols=1, sharex=False, sharey=False, squeeze=True, sharey = "none" share_values = ["all", "row", "col", "none"] if sharex not in share_values: + # 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. + if isinstance(sharex, int) : + warnings.warn("sharex argument to subplots() was not boolean." + " Did you intend to use subplot()?") + raise ValueError("sharex [%s] must be one of %s" % \ (sharex, share_values)) if sharey not in share_values: From 92d2ae3fc3f043ab5fcd6ce2da76517671be88a2 Mon Sep 17 00:00:00 2001 From: Benjamin Root Date: Fri, 6 Jul 2012 21:39:43 -0400 Subject: [PATCH 2/2] Correcting for a bad rebase. --- lib/matplotlib/pyplot.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/lib/matplotlib/pyplot.py b/lib/matplotlib/pyplot.py index d169d392201d..f7199098bc72 100644 --- a/lib/matplotlib/pyplot.py +++ b/lib/matplotlib/pyplot.py @@ -911,16 +911,15 @@ def subplots(nrows=1, ncols=1, sharex=False, sharey=False, squeeze=True, # ever occur, but mysterious behavior will result because what was # intended to be the subplot index is instead treated as a bool for # sharex. - if isinstance(sharex, int) : - warnings.warn("sharex argument to subplots() was not boolean." - " Did you intend to use subplot()?") + if isinstance(sharex, int): + warnings.warn("sharex argument to subplots() was an integer." + " Did you intend to use subplot() (without 's')?") raise ValueError("sharex [%s] must be one of %s" % \ (sharex, share_values)) if sharey not in share_values: raise ValueError("sharey [%s] must be one of %s" % \ (sharey, share_values)) - if subplot_kw is None: subplot_kw = {}