From c16aa8cb2af1b0fd463873e4dc9c6058a6bf936f Mon Sep 17 00:00:00 2001 From: Paul Kirow Date: Thu, 17 Mar 2016 18:51:30 -0400 Subject: [PATCH 1/3] Adds targetfig parameter to the subplot2grid function As mentioned in issue #6105 --- lib/matplotlib/pyplot.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/matplotlib/pyplot.py b/lib/matplotlib/pyplot.py index c9b8999dbfe..05d611e95cf 100644 --- a/lib/matplotlib/pyplot.py +++ b/lib/matplotlib/pyplot.py @@ -1147,7 +1147,7 @@ def subplots(nrows=1, ncols=1, sharex=False, sharey=False, squeeze=True, return fig, axs -def subplot2grid(shape, loc, rowspan=1, colspan=1, **kwargs): +def subplot2grid(shape, loc, rowspan=1, colspan=1, targetfig=None, **kwargs): """ Create a subplot in a grid. The grid is specified by *shape*, at location of *loc*, spanning *rowspan*, *colspan* cells in each @@ -1162,7 +1162,11 @@ def subplot2grid(shape, loc, rowspan=1, colspan=1, **kwargs): subplot(subplotspec) """ - fig = gcf() + if targetfig is None: + fig = gcf() + else: + fig = targetfig + s1, s2 = shape subplotspec = GridSpec(s1, s2).new_subplotspec(loc, rowspan=rowspan, From ec5458023d4532e69a12f5c75f9b90346ad1077e Mon Sep 17 00:00:00 2001 From: Paul Kirow Date: Fri, 18 Mar 2016 00:28:57 -0400 Subject: [PATCH 2/3] Renamed parameter and removed redundancy --- lib/matplotlib/pyplot.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/lib/matplotlib/pyplot.py b/lib/matplotlib/pyplot.py index 05d611e95cf..923c33ad015 100644 --- a/lib/matplotlib/pyplot.py +++ b/lib/matplotlib/pyplot.py @@ -1147,7 +1147,7 @@ def subplots(nrows=1, ncols=1, sharex=False, sharey=False, squeeze=True, return fig, axs -def subplot2grid(shape, loc, rowspan=1, colspan=1, targetfig=None, **kwargs): +def subplot2grid(shape, loc, rowspan=1, colspan=1, fig=None, **kwargs): """ Create a subplot in a grid. The grid is specified by *shape*, at location of *loc*, spanning *rowspan*, *colspan* cells in each @@ -1162,10 +1162,8 @@ def subplot2grid(shape, loc, rowspan=1, colspan=1, targetfig=None, **kwargs): subplot(subplotspec) """ - if targetfig is None: + if fig is None: fig = gcf() - else: - fig = targetfig s1, s2 = shape subplotspec = GridSpec(s1, s2).new_subplotspec(loc, From 946631817cc9f7c0e5ebbfb15585929ab123189f Mon Sep 17 00:00:00 2001 From: Paul Kirow Date: Sun, 20 Mar 2016 11:01:03 -0400 Subject: [PATCH 3/3] Updated docstring and created whats_new document These changes are meant to document the added parameter to the subplot2grid method --- doc/users/whats_new/uptade_subplot2grid.rst | 13 +++++++++++++ lib/matplotlib/pyplot.py | 3 ++- 2 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 doc/users/whats_new/uptade_subplot2grid.rst diff --git a/doc/users/whats_new/uptade_subplot2grid.rst b/doc/users/whats_new/uptade_subplot2grid.rst new file mode 100644 index 00000000000..2b6b96823a2 --- /dev/null +++ b/doc/users/whats_new/uptade_subplot2grid.rst @@ -0,0 +1,13 @@ +New Firgure Parameter for subplot2grid +-------------------------------------- + +A ``fig`` parameter now exists for the method :func:`subplot2grid`. This allows +for the figure that the subplots will be created in to be specified. If ``fig`` +is ``None`` (default) then the method will use the current figure retrieved by +:func:`gcf`. + +Example +``````` +:: + + subplot2grid(shape, loc, rowspan=1, colspan=1, fig=myfig) diff --git a/lib/matplotlib/pyplot.py b/lib/matplotlib/pyplot.py index 923c33ad015..5ea396df7df 100644 --- a/lib/matplotlib/pyplot.py +++ b/lib/matplotlib/pyplot.py @@ -1151,7 +1151,8 @@ def subplot2grid(shape, loc, rowspan=1, colspan=1, fig=None, **kwargs): """ Create a subplot in a grid. The grid is specified by *shape*, at location of *loc*, spanning *rowspan*, *colspan* cells in each - direction. The index for loc is 0-based. :: + direction. The index for loc is 0-based. The current figure will + be used unless *fig* is specified. :: subplot2grid(shape, loc, rowspan=1, colspan=1)