@@ -807,8 +807,7 @@ def subplots(self, nrows=1, ncols=1, sharex=False, sharey=False,
807
807
Number of rows/columns of the subplot grid.
808
808
809
809
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*):
812
811
813
812
- True or 'all': x- or y-axis will be shared among all subplots.
814
813
- False or 'none': each subplot x- or y-axis will be independent.
@@ -1672,8 +1671,8 @@ def _normalize_grid_string(layout):
1672
1671
layout = inspect .cleandoc (layout )
1673
1672
return [list (ln ) for ln in layout .strip ('\n ' ).split ('\n ' )]
1674
1673
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 = '.' ):
1677
1676
"""
1678
1677
Build a layout of Axes based on ASCII art or nested lists.
1679
1678
@@ -1684,7 +1683,6 @@ def subplot_mosaic(self, layout, *, subplot_kw=None, gridspec_kw=None,
1684
1683
This API is provisional and may be revised in the future based on
1685
1684
early user feedback.
1686
1685
1687
-
1688
1686
Parameters
1689
1687
----------
1690
1688
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,
1695
1693
x = [['A panel', 'A panel', 'edge'],
1696
1694
['C panel', '.', 'edge']]
1697
1695
1698
- Produces 4 Axes:
1696
+ produces 4 Axes:
1699
1697
1700
1698
- 'A panel' which is 1 row high and spans the first two columns
1701
1699
- '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,
1721
1719
The string notation allows only single character Axes labels and
1722
1720
does not support nesting but is very terse.
1723
1721
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
+
1724
1728
subplot_kw : dict, optional
1725
1729
Dictionary with keywords passed to the `.Figure.add_subplot` call
1726
1730
used to create each subplot.
@@ -1905,6 +1909,16 @@ def _do_layout(gs, layout, unique_ids, nested):
1905
1909
rows , cols = layout .shape
1906
1910
gs = self .add_gridspec (rows , cols , ** gridspec_kw )
1907
1911
ret = _do_layout (gs , layout , * _identify_keys_and_nested (layout ))
1912
+ ax0 = next (iter (ret .values ()))
1913
+ # Only accept strict bools to allow a possible future API expansion.
1914
+ _api .check_isinstance (bool , sharex = sharex , sharey = sharey )
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 ()
1908
1922
for k , ax in ret .items ():
1909
1923
if isinstance (k , str ):
1910
1924
ax .set_label (k )
0 commit comments