X Tutup
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions doc/users/whats_new/uptade_subplot2grid.rst
Original file line number Diff line number Diff line change
@@ -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)
9 changes: 6 additions & 3 deletions lib/matplotlib/pyplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -1147,11 +1147,12 @@ 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, 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)

Expand All @@ -1162,7 +1163,9 @@ def subplot2grid(shape, loc, rowspan=1, colspan=1, **kwargs):
subplot(subplotspec)
"""

fig = gcf()
if fig is None:
fig = gcf()

s1, s2 = shape
subplotspec = GridSpec(s1, s2).new_subplotspec(loc,
rowspan=rowspan,
Expand Down
X Tutup