@@ -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.
@@ -1672,8 +1671,8 @@ def _normalize_grid_string(layout):
16721671 layout = inspect .cleandoc (layout )
16731672 return [list (ln ) for ln in layout .strip ('\n ' ).split ('\n ' )]
16741673
1675- def subplot_mosaic (self , layout , * , subplot_kw = None , gridspec_kw = None ,
1676- empty_sentinel = '.' ):
1674+ def subplot_mosaic (self , layout , * , sharex = False , sharey = False ,
1675+ subplot_kw = None , gridspec_kw = None , empty_sentinel = '.' ):
16771676 """
16781677 Build a layout of Axes based on ASCII art or nested lists.
16791678
@@ -1684,7 +1683,6 @@ def subplot_mosaic(self, layout, *, subplot_kw=None, gridspec_kw=None,
16841683 This API is provisional and may be revised in the future based on
16851684 early user feedback.
16861685
1687-
16881686 Parameters
16891687 ----------
16901688 layout : list of list of {hashable or nested} or str
@@ -1695,7 +1693,7 @@ def subplot_mosaic(self, layout, *, subplot_kw=None, gridspec_kw=None,
16951693 x = [['A panel', 'A panel', 'edge'],
16961694 ['C panel', '.', 'edge']]
16971695
1698- Produces 4 Axes:
1696+ produces 4 Axes:
16991697
17001698 - 'A panel' which is 1 row high and spans the first two columns
17011699 - 'edge' which is 2 rows high and is on the right edge
@@ -1721,6 +1719,12 @@ def subplot_mosaic(self, layout, *, subplot_kw=None, gridspec_kw=None,
17211719 The string notation allows only single character Axes labels and
17221720 does not support nesting but is very terse.
17231721
1722+ sharex, sharey : bool, default: False
1723+ If True, the x-axis (*sharex*) or y-axis (*sharey*) will be shared
1724+ among all subplots. In that case, tick label visibility and axis
1725+ units behave as for `subplots`. If False, each subplot's x- or
1726+ y-axis will be independent.
1727+
17241728 subplot_kw : dict, optional
17251729 Dictionary with keywords passed to the `.Figure.add_subplot` call
17261730 used to create each subplot.
@@ -1748,6 +1752,8 @@ def subplot_mosaic(self, layout, *, subplot_kw=None, gridspec_kw=None,
17481752 # special-case string input
17491753 if isinstance (layout , str ):
17501754 layout = self ._normalize_grid_string (layout )
1755+ # Only accept strict bools to allow a possible future API expansion.
1756+ _api .check_isinstance (bool , sharex = sharex , sharey = sharey )
17511757
17521758 def _make_array (inp ):
17531759 """
@@ -1905,6 +1911,14 @@ def _do_layout(gs, layout, unique_ids, nested):
19051911 rows , cols = layout .shape
19061912 gs = self .add_gridspec (rows , cols , ** gridspec_kw )
19071913 ret = _do_layout (gs , layout , * _identify_keys_and_nested (layout ))
1914+ ax0 = next (iter (ret .values ()))
1915+ for ax in ret .values ():
1916+ if sharex :
1917+ ax .sharex (ax0 )
1918+ ax ._label_outer_xaxis ()
1919+ if sharey :
1920+ ax .sharey (ax0 )
1921+ ax ._label_outer_yaxis ()
19081922 for k , ax in ret .items ():
19091923 if isinstance (k , str ):
19101924 ax .set_label (k )
0 commit comments