Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 0003470

Browse files
committed
Merge pull request #6179 from paulkirow/d01f1
ENH: Adds targetfig parameter to the subplot2grid function closes #6105:
2 parents b64bd25 + 9466318 commit 0003470

2 files changed

Lines changed: 19 additions & 3 deletions

File tree

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
New Firgure Parameter for subplot2grid
2+
--------------------------------------
3+
4+
A ``fig`` parameter now exists for the method :func:`subplot2grid`. This allows
5+
for the figure that the subplots will be created in to be specified. If ``fig``
6+
is ``None`` (default) then the method will use the current figure retrieved by
7+
:func:`gcf`.
8+
9+
Example
10+
```````
11+
::
12+
13+
subplot2grid(shape, loc, rowspan=1, colspan=1, fig=myfig)

lib/matplotlib/pyplot.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1147,11 +1147,12 @@ def subplots(nrows=1, ncols=1, sharex=False, sharey=False, squeeze=True,
11471147
return fig, axs
11481148

11491149

1150-
def subplot2grid(shape, loc, rowspan=1, colspan=1, **kwargs):
1150+
def subplot2grid(shape, loc, rowspan=1, colspan=1, fig=None, **kwargs):
11511151
"""
11521152
Create a subplot in a grid. The grid is specified by *shape*, at
11531153
location of *loc*, spanning *rowspan*, *colspan* cells in each
1154-
direction. The index for loc is 0-based. ::
1154+
direction. The index for loc is 0-based. The current figure will
1155+
be used unless *fig* is specified. ::
11551156
11561157
subplot2grid(shape, loc, rowspan=1, colspan=1)
11571158
@@ -1162,7 +1163,9 @@ def subplot2grid(shape, loc, rowspan=1, colspan=1, **kwargs):
11621163
subplot(subplotspec)
11631164
"""
11641165

1165-
fig = gcf()
1166+
if fig is None:
1167+
fig = gcf()
1168+
11661169
s1, s2 = shape
11671170
subplotspec = GridSpec(s1, s2).new_subplotspec(loc,
11681171
rowspan=rowspan,

0 commit comments

Comments
 (0)