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

Skip to content

Commit 4a4391b

Browse files
committed
FIX
1 parent e16ab73 commit 4a4391b

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

lib/matplotlib/gridspec.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,8 @@ def get_grid_positions(self, fig, raw=False):
200200
@staticmethod
201201
def _check_gridspec_exists(figure, nrows, ncols):
202202
"""
203-
Check if the figure already has a gridspec with these dimensions...
203+
Check if the figure already has a gridspec with these dimensions,
204+
or create a new one
204205
"""
205206
gs = None
206207
for ax in figure.get_axes():
@@ -217,6 +218,8 @@ def _check_gridspec_exists(figure, nrows, ncols):
217218
(nrow, ncol) = ggs.get_geometry()
218219
if nrow == nrows and ncol == ncols:
219220
gs = ggs
221+
if gs is None:
222+
gs = GridSpec(nrows, ncols, figure=figure)
220223
return gs
221224

222225

@@ -583,8 +586,7 @@ def _from_subplot_args(figure, args):
583586
f"{len(args)} were given")
584587

585588
gs = GridSpec._check_gridspec_exists(figure, rows, cols)
586-
if gs is None:
587-
gs = GridSpec(rows, cols, figure=figure)
589+
588590
return gs[ii-1:jj]
589591

590592

lib/matplotlib/pyplot.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1239,8 +1239,6 @@ def subplot2grid(shape, loc, rowspan=1, colspan=1, fig=None, **kwargs):
12391239

12401240
rows, cols = shape
12411241
gs = GridSpec._check_gridspec_exists(fig, rows, cols)
1242-
if gs is None:
1243-
gs = GridSpec(rows, cols, figure=fig)
12441242

12451243
subplotspec = gs.new_subplotspec(loc, rowspan=rowspan, colspan=colspan)
12461244
ax = fig.add_subplot(subplotspec, **kwargs)

0 commit comments

Comments
 (0)