From bf83c161a6907009489ba8970ca30a81175c9905 Mon Sep 17 00:00:00 2001 From: Paul Ivanov Date: Fri, 9 Nov 2012 23:19:52 -0800 Subject: [PATCH 1/2] make plt.subplot() act as plt.subplot(111) Since plt.subplots() make an assumption of what you want when you call it without arguments, and as does plt.axes(), there's no reason why plt.subplot() shouldn't make the same assumption. --- CHANGELOG | 2 ++ lib/matplotlib/pyplot.py | 7 +++++++ 2 files changed, 9 insertions(+) diff --git a/CHANGELOG b/CHANGELOG index 1124187a8d84..37159d5941d7 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,5 @@ +2012-11-09 Make plt.subplot() without arguments act as subplot(111) - PI + 2012-10-05 Add support for saving animations as animated GIFs. - JVDP 2012-08-11 Fix path-closing bug in patches.Polygon, so that regardless diff --git a/lib/matplotlib/pyplot.py b/lib/matplotlib/pyplot.py index 997382e47d44..4dd2f44504ba 100644 --- a/lib/matplotlib/pyplot.py +++ b/lib/matplotlib/pyplot.py @@ -727,6 +727,9 @@ def subplot(*args, **kwargs): ``subplot(111)`` is the default axis. + ``subplot()`` by itself is the same as ``subplot(111)`` + + New subplots that overlap old will delete the old axes. If you do not want this behavior, use :meth:`~matplotlib.figure.Figure.add_subplot` or the @@ -768,6 +771,10 @@ def subplot(*args, **kwargs): .. plot:: mpl_examples/pylab_examples/subplot_demo.py """ + # if subplot called without arguments, create subplot(1,1,1) + if len(args)==0: + args=(1,1,1) + # 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 From 31e0a104f98140be485e41eb3ee7d613a99db86e Mon Sep 17 00:00:00 2001 From: Paul Ivanov Date: Sun, 11 Nov 2012 22:58:57 -0800 Subject: [PATCH 2/2] DOC: whats_new: plt.subplot without args behaviour --- doc/users/whats_new.rst | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/doc/users/whats_new.rst b/doc/users/whats_new.rst index ce2fd09c57e3..d09c6732af14 100644 --- a/doc/users/whats_new.rst +++ b/doc/users/whats_new.rst @@ -26,6 +26,13 @@ Andrew Dawson added a new keyword argument *extendrect* to :meth:`~matplotlib.pyplot.colorbar` to optionally make colorbar extensions rectangular instead of triangular. +Calling subplot() without arguments +----------------------------------- +A call to :func:`~matplotlib.pyplot.subplot` without any arguments now +acts the same as `subplot(111)` or `subplot(1,1,1)` -- it creates one axes for +the whole figure. This was already the behavior for both +:func:`~matplotlib.pyplot.axes` and :func:`~matplotlib.pyplot.subplots`, and +now this consistency is shared with :func:`~matplotlib.pyplot.subplot`. .. _whats-new-1-2: