Skip to content

Commit 4c48f7e

Browse files
committed
Single-line string notation for subplot_mosaic
1 parent cf83ec4 commit 4c48f7e

File tree

1 file changed

+16
-6
lines changed

1 file changed

+16
-6
lines changed

lib/matplotlib/figure.py

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1776,8 +1776,13 @@ def get_tightbbox(self, renderer, bbox_extra_artists=None):
17761776

17771777
@staticmethod
17781778
def _normalize_grid_string(layout):
1779-
layout = inspect.cleandoc(layout)
1780-
return [list(ln) for ln in layout.strip('\n').split('\n')]
1779+
if '\n' not in layout:
1780+
# single-line string
1781+
return [list(ln) for ln in layout.split(';')]
1782+
else:
1783+
# multi-line string
1784+
layout = inspect.cleandoc(layout)
1785+
return [list(ln) for ln in layout.strip('\n').split('\n')]
17811786

17821787
def subplot_mosaic(self, layout, *, subplot_kw=None, gridspec_kw=None,
17831788
empty_sentinel='.'):
@@ -1812,16 +1817,21 @@ def subplot_mosaic(self, layout, *, subplot_kw=None, gridspec_kw=None,
18121817
Any of the entries in the layout can be a list of lists
18131818
of the same form to create nested layouts.
18141819
1815-
If input is a str, then it must be of the form ::
1820+
If input is a str, then it can either be a multi-line string of
1821+
the form ::
18161822
18171823
'''
18181824
AAE
18191825
C.E
18201826
'''
18211827
1822-
where each character is a column and each line is a row.
1823-
This only allows only single character Axes labels and does
1824-
not allow nesting but is very terse.
1828+
where each character is a column and each line is a row. Or it
1829+
can be a single-line string where rows are separated by ``;``::
1830+
1831+
'AB;CC'
1832+
1833+
The string notation allows only single character Axes labels and
1834+
does not support nesting but is very terse.
18251835
18261836
subplot_kw : dict, optional
18271837
Dictionary with keywords passed to the `.Figure.add_subplot` call

0 commit comments

Comments
 (0)