@@ -1584,7 +1584,7 @@ def build_grid(self, layout, *, subplot_kw=None, gridspec_kw=None,
1584
1584
1585
1585
Parameters
1586
1586
----------
1587
- layout : list of list of str
1587
+ layout : list of list of { str, int, Axes} or nested
1588
1588
1589
1589
A visual layout of how you want your Axes to be arranged
1590
1590
labeled as strings. For example ::
@@ -1629,7 +1629,7 @@ def _process_layout(layout):
1629
1629
for k , v in enumerate (row ):
1630
1630
if v == empty_sentinal :
1631
1631
continue
1632
- elif isinstance (v , (str , Axes )):
1632
+ elif isinstance (v , (int , str , Axes )):
1633
1633
unique_ids .add (v )
1634
1634
else :
1635
1635
nested [(j , k )] = v
@@ -1654,13 +1654,16 @@ def _do_layout(gs, layout, unique_ids, nested):
1654
1654
covered [slc ] = True
1655
1655
if name == empty_sentinal :
1656
1656
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' ):
1660
1659
ax = name
1661
1660
ax .set_subplotspec (gs [slc ])
1662
1661
ax .update_params ()
1663
1662
ax .set_position (ax .figbox )
1663
+ output [id (ax )] = ax
1664
+ else :
1665
+ output [name ] = self .add_subplot (
1666
+ gs [slc ], ** subplot_kw )
1664
1667
1665
1668
for (j , k ), layout in nested .items ():
1666
1669
layout = np .asarray (layout )
@@ -1672,7 +1675,7 @@ def _do_layout(gs, layout, unique_ids, nested):
1672
1675
output .update (nested_output )
1673
1676
return output
1674
1677
1675
- layout = np .asarray (layout )
1678
+ layout = np .asarray (layout , dtype = object )
1676
1679
rows , cols = layout .shape
1677
1680
gs = GridSpec (rows , cols , figure = self , ** gridspec_kw )
1678
1681
return _do_layout (gs , layout , * _process_layout (layout ))
0 commit comments