@@ -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':
10000
each subplot x- or y-axis will be independent.
@@ -1649,8 +1648,8 @@ def _normalize_grid_string(layout):
1649
1648
layout = inspect .cleandoc (layout )
1650
1649
return [list (ln ) for ln in layout .strip ('\n ' ).split ('\n ' )]
1651
1650
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 = '.' ):
1654
1653
"""
1655
1654
Build a layout of Axes based on ASCII art or nested lists.
1656
1655
@@ -1661,7 +1660,6 @@ def subplot_mosaic(self, layout, *, subplot_kw=None, gridspec_kw=None,
1661
1660
This API is provisional and may be revised in the future based on
1662
1661
early user feedback.
1663
1662
1664
-
1665
1663
Parameters
1666
1664
----------
1667
1665
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,
1672
1670
x = [['A panel', 'A panel', 'edge'],
1673
1671
['C panel', '.', 'edge']]
1674
1672
1675
- Produces 4 Axes:
1673
+ produces 4 Axes:
1676
1674
1677
1675
- 'A panel' which is 1 row high and spans the first two columns
1678
1676
- '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,
1698
1696
The string notation allows only single character Axes labels and
1699
1697
does not support nesting but is very terse.
1700
1698
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
+
1701
1705
subplot_kw : dict, optional
1702
1706
Dictionary with keywords passed to the `.Figure.add_subplot` call
1703
1707
used to create each subplot.
@@ -1725,6 +1729,8 @@ def subplot_mosaic(self, layout, *, subplot_kw=None, gridspec_kw=None,
1725
1729
# special-case string input
1726
1730
if isinstance (layout , str ):
1727
1731
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 )
1728
1734
1729
1735
def _make_array (inp ):
1730
1736
"""
@@ -1882,6 +1888,14 @@ def _do_layout(gs, layout, unique_ids, nested):
1882
1888
rows , cols = layout .shape
1883
1889
gs = self .add_gridspec (rows , cols , ** gridspec_kw )
1884
1890
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 ()
1885
1899
for k , ax in ret .items ():
1886
1900
if isinstance (k , str ):
1887
1901
ax .set_label (k )
0 commit comments