@@ -807,8 +807,7 @@ def subplots(self, nrows=1, ncols=1, sharex=False, sharey=False,
807807 Number of rows/columns of the subplot grid.
808808
809809 sharex, sharey : bool or {'none', 'all', 'row', 'col'}, default: False
810- Controls sharing of properties among x (*sharex*) or y (*sharey*)
811- axes:
810+ Controls sharing of x-axis (*sharex*) or y-axis (*sharey*):
812811
813812 - True or 'all': x- or y-axis will be shared among all subplots.
814813 - False or 'none': each subplot x- or y-axis will be independent.
@@ -1649,8 +1648,8 @@ def _normalize_grid_string(layout):
16491648 layout = inspect .cleandoc (layout )
16501649 return [list (ln ) for ln in layout .strip ('\n ' ).split ('\n ' )]
16511650
1652- def subplot_mosaic (self , layout , * , subplot_kw = None , gridspec_kw = None ,
1653- empty_sentinel = '.' ):
1651+ def subplot_mosaic (self , layout , * , sharex = False , sharey = False ,
1652+ subplot_kw = None , gridspec_kw = None , empty_sentinel = '.' ):
16541653 """
16551654 Build a layout of Axes based on ASCII art or nested lists.
16561655
@@ -1661,7 +1660,6 @@ def subplot_mosaic(self, layout, *, subplot_kw=None, gridspec_kw=None,
16611660 This API is provisional and may be revised in the future based on
16621661 early user feedback.
16631662
1664-
16651663 Parameters
16661664 ----------
16671665 layout : list of list of {hashable or nested} or str
@@ -1672,7 +1670,7 @@ def subplot_mosaic(self, layout, *, subplot_kw=None, gridspec_kw=None,
16721670 x = [['A panel', 'A panel', 'edge'],
16731671 ['C panel', '.', 'edge']]
16741672
1675- Produces 4 Axes:
1673+ produces 4 Axes:
16761674
16771675 - 'A panel' which is 1 row high and spans the first two columns
16781676 - 'edge' which is 2 rows high and is on the right edge
@@ -1698,6 +1696,12 @@ def subplot_mosaic(self, layout, *, subplot_kw=None, gridspec_kw=None,
16981696 The string notation allows only single character Axes labels and
16991697 does not support nesting but is very terse.
17001698
1699+ sharex, sharey : bool, default: False
1700+ If True, the x-axis (*sharex*) or y-axis (*sharey*) will be shared
1701+ among all subplots. In that case, tick label visibility and axis
1702+ units behave as for `subplots`. If False, each subplot's x- or
1703+ y-axis will be independent.
1704+
17011705 subplot_kw : dict, optional
17021706 Dictionary with keywords passed to the `.Figure.add_subplot` call
17031707 used to create each subplot.
@@ -1725,6 +1729,8 @@ def subplot_mosaic(self, layout, *, subplot_kw=None, gridspec_kw=None,
17251729 # special-case string input
17261730 if isinstance (layout , str ):
17271731 layout = self ._normalize_grid_string (layout )
1732+ # Only accept strict bools to allow a possible future API expansion.
1733+ _api .check_isinstance (bool , sharex = sharex , sharey = sharey )
17281734
17291735 def _make_array (inp ):
17301736 """
@@ -1882,6 +1888,14 @@ def _do_layout(gs, layout, unique_ids, nested):
18821888 rows , cols = layout .shape
18831889 gs = self .add_gridspec (rows , cols , ** gridspec_kw )
18841890 ret = _do_layout (gs , layout , * _identify_keys_and_nested (layout ))
1891+ ax0 = next (iter (ret .values ()))
1892+ for ax in ret .values ():
1893+ if sharex :
1894+ ax .sharex (ax0 )
1895+ ax ._label_outer_xaxis ()
1896+ if sharey :
1897+ ax .sharey (ax0 )
1898+ ax ._label_outer_yaxis ()
18851899 for k , ax in ret .items ():
18861900 if isinstance (k , str ):
18871901 ax .set_label (k )
0 commit comments