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

Skip to content

Commit 1939911

Browse files
committed
ENH: support integers as (in addition to strings)
1 parent d29d0d9 commit 1939911

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

lib/matplotlib/figure.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1584,7 +1584,7 @@ def build_grid(self, layout, *, subplot_kw=None, gridspec_kw=None,
15841584
15851585
Parameters
15861586
----------
1587-
layout : list of list of str
1587+
layout : list of list of {str, int, Axes} or nested
15881588
15891589
A visual layout of how you want your Axes to be arranged
15901590
labeled as strings. For example ::
@@ -1629,7 +1629,7 @@ def _process_layout(layout):
16291629
for k, v in enumerate(row):
16301630
if v == empty_sentinal:
16311631
continue
1632-
elif isinstance(v, (str, Axes)):
1632+
elif isinstance(v, (int, str, Axes)):
16331633
unique_ids.add(v)
16341634
else:
16351635
nested[(j, k)] = v
@@ -1654,13 +1654,16 @@ def _do_layout(gs, layout, unique_ids, nested):
16541654
covered[slc] = True
16551655
if name == empty_sentinal:
16561656
continue
1657-
if isinstance(name, str):
1658-
output[name] = self.add_subplot(gs[slc], **subplot_kw)
1659-
else:
1657+
1658+
if hasattr(name, 'set_subplotspec'):
16601659
ax = name
16611660
ax.set_subplotspec(gs[slc])
16621661
ax.update_params()
16631662
ax.set_position(ax.figbox)
1663+
output[id(ax)] = ax
1664+
else:
1665+
output[name] = self.add_subplot(
1666+
gs[slc], **subplot_kw)
16641667

16651668
for (j, k), layout in nested.items():
16661669
layout = np.asarray(layout)
@@ -1672,7 +1675,7 @@ def _do_layout(gs, layout, unique_ids, nested):
16721675
output.update(nested_output)
16731676
return output
16741677

1675-
layout = np.asarray(layout)
1678+
layout = np.asarray(layout, dtype=object)
16761679
rows, cols = layout.shape
16771680
gs = GridSpec(rows, cols, figure=self, **gridspec_kw)
16781681
return _do_layout(gs, layout, *_process_layout(layout))

0 commit comments

Comments
 (0)