@@ -1649,7 +1649,7 @@ def _normalize_grid_string(layout):
1649
1649
layout = inspect .cleandoc (layout )
1650
1650
return [list (ln ) for ln in layout .strip ('\n ' ).split ('\n ' )]
1651
1651
1652
- def subplot_mosaic (self , layout , * , sharex = False , sharey = False ,
1652
+ def subplot_mosaic (self , mosaic , * , sharex = False , sharey = False ,
1653
1653
subplot_kw = None , gridspec_kw = None , empty_sentinel = '.' ):
1654
1654
"""
1655
1655
Build a layout of Axes based on ASCII art or nested lists.
@@ -1663,7 +1663,7 @@ def subplot_mosaic(self, layout, *, sharex=False, sharey=False,
1663
1663
1664
1664
Parameters
1665
1665
----------
1666
- layout : list of list of {hashable or nested} or str
1666
+ mosaic : list of list of {hashable or nested} or str
1667
1667
1668
1668
A visual layout of how you want your Axes to be arranged
1669
1669
labeled as strings. For example ::
@@ -1728,8 +1728,8 @@ def subplot_mosaic(self, layout, *, sharex=False, sharey=False,
1728
1728
subplot_kw = subplot_kw or {}
1729
1729
gridspec_kw = gridspec_kw or {}
1730
1730
# special-case string input
1731
- if isinstance (layout , str ):
1732
- layout = self ._normalize_grid_string (layout )
1731
+ if isinstance (mosaic , str ):
1732
+ mosaic = self ._normalize_grid_string (mosaic )
1733
1733
# Only accept strict bools to allow a possible future API expansion.
1734
1734
_api .check_isinstance (bool , sharex = sharex , sharey = sharey )
1735
1735
@@ -1749,10 +1749,10 @@ def _make_array(inp):
1749
1749
"""
1750
1750
r0 , * rest = inp
1751
1751
if isinstance (r0 , str ):
1752
- raise ValueError ('List layout specification must be 2D' )
1752
+ raise ValueError ('List mosaic specification must be 2D' )
1753
1753
for j , r in enumerate (rest , start = 1 ):
1754
1754
if isinstance (r , str ):
1755
- raise ValueError ('List layout specification must be 2D' )
1755
+ raise ValueError ('List mosaic specification must be 2D' )
1756
1756
if len (r0 ) != len (r ):
1757
1757
raise ValueError (
1758
1758
"All of the rows must be the same length, however "
@@ -1765,24 +1765,24 @@ def _make_array(inp):
1765
1765
out [j , k ] = v
1766
1766
return out
1767
1767
1768
- def _identify_keys_and_nested (layout ):
1768
+ def _identify_keys_and_nested (mosaic ):
1769
1769
"""
1770
- Given a 2D object array, identify unique IDs and nested layouts
1770
+ Given a 2D object array, identify unique IDs and nested mosaics
1771
1771
1772
1772
Parameters
1773
1773
----------
1774
- layout : 2D numpy object array
1774
+ mosaic : 2D numpy object array
1775
1775
1776
1776
Returns
1777
1777
-------
1778
1778
unique_ids : tuple
1779
- The unique non-sub layout entries in this layout
1779
+ The unique non-sub mosaic entries in this mosaic
1780
1780
nested : dict[tuple[int, int]], 2D object array
1781
1781
"""
1782
1782
# make sure we preserve the user supplied order
1783
1783
unique_ids = cbook ._OrderedSet ()
1784
1784
nested = {}
1785
- for j , row in enumerate (layout ):
1785
+ for j , row in enumerate (mosaic ):
1786
1786
for k , v in enumerate (row ):
1787
1787
if v == empty_sentinel :
1788
1788
continue
@@ -1793,102 +1793,102 @@ def _identify_keys_and_nested(layout):
1793
1793
1794
1794
return tuple (unique_ids ), nested
1795
1795
1796
- def _do_layout (gs , layout , unique_ids , nested ):
1796
+ def _do_layout (gs , mosaic , unique_ids , nested ):
1797
1797
"""
1798
- Recursively do the layout .
1798
+ Recursively do the mosaic .
1799
1799
1800
1800
Parameters
1801
1801
----------
1802
1802
gs : GridSpec
1803
- layout : 2D object array
1803
+ mosaic : 2D object array
1804
1804
The input converted to a 2D numpy array for this level.
1805
1805
unique_ids : tuple
1806
1806
The identified scalar labels at this level of nesting.
1807
1807
nested : dict[tuple[int, int]], 2D object array
1808
- The identified nested layouts , if any.
1808
+ The identified nested mosaics , if any.
1809
1809
1810
1810
Returns
1811
1811
-------
1812
1812
dict[label, Axes]
1813
1813
A flat dict of all of the Axes created.
1814
1814
"""
1815
- rows , cols = layout .shape
1815
+ rows , cols = mosaic .shape
1816
1816
output = dict ()
1817
1817
1818
1818
# we need to merge together the Axes at this level and the axes
1819
- # in the (recursively) nested sub-layouts so that we can add
1819
+ # in the (recursively) nested sub-mosaics so that we can add
1820
1820
# them to the figure in the "natural" order if you were to
1821
1821
# ravel in c-order all of the Axes that will be created
1822
1822
#
1823
1823
# This will stash the upper left index of each object (axes or
1824
- # nested layout ) at this level
1824
+ # nested mosaic ) at this level
1825
1825
this_level = dict ()
1826
1826
1827
1827
# go through the unique keys,
1828
1828
for name in unique_ids :
1829
1829
# sort out where each axes starts/ends
1830
- indx = np .argwhere (layout == name )
1830
+ indx = np .argwhere (mosaic == name )
1831
1831
start_row , start_col = np .min (indx , axis = 0 )
1832
1832
end_row , end_col = np .max (indx , axis = 0 ) + 1
1833
1833
# and construct the slice object
1834
1834
slc = (slice (start_row , end_row ), slice (start_col , end_col ))
1835
1835
# some light error checking
1836
- if (layout [slc ] != name ).any ():
1836
+ if (mosaic [slc ] != name ).any ():
1837
1837
raise ValueError (
1838
- f"While trying to layout\n { layout !r} \n "
1838
+ f"While trying to layout\n { mosaic !r} \n "
1839
1839
f"we found that the label { name !r} specifies a "
1840
1840
"non-rectangular or non-contiguous area." )
1841
1841
# and stash this slice for later
1842
1842
this_level [(start_row , start_col )] = (name , slc , 'axes' )
1843
1843
1844
- # do the same thing for the nested layouts (simpler because these
1844
+ # do the same thing for the nested mosaics (simpler because these
1845
1845
# can not be spans yet!)
1846
- for (j , k ), nested_layout in nested .items ():
1847
- this_level [(j , k )] = (None , nested_layout , 'nested' )
1846
+ for (j , k ), nested_mosaic in nested .items ():
1847
+ this_level [(j , k )] = (None , nested_mosaic , 'nested' )
1848
1848
1849
1849
# now go through the things in this level and add them
1850
1850
# in order left-to-right top-to-bottom
1851
1851
for key in sorted (this_level ):
1852
1852
name , arg , method = this_level [key ]
1853
1853
# we are doing some hokey function dispatch here based
1854
1854
# on the 'method' string stashed above to sort out if this
1855
- # element is an axes or a nested layout .
1855
+ # element is an axes or a nested mosaic .
1856
1856
if method == 'axes' :
1857
1857
slc = arg
1858
1858
# add a single axes
1859
1859
if name in output :
1860
1860
raise ValueError (f"There are duplicate keys { name } "
1861
- f"in the layout\n { layout !r} " )
1861
+ f"in the layout\n { mosaic !r} " )
1862
1862
ax = self .add_subplot (
1863
1863
gs [slc ], ** {'label' : str (name ), ** subplot_kw }
1864
1864
)
1865
1865
output [name ] = ax
1866
1866
elif method == 'nested' :
1867
- nested_layout = arg
1867
+ nested_mosaic = arg
1868
1868
j , k = key
1869
- # recursively add the nested layout
1870
- rows , cols = nested_layout .shape
1869
+ # recursively add the nested mosaic
1870
+ rows , cols = nested_mosaic .shape
1871
1871
nested_output = _do_layout (
1872
1872
gs [j , k ].subgridspec (rows , cols , ** gridspec_kw ),
1873
- nested_layout ,
1874
- * _identify_keys_and_nested (nested_layout )
1873
+ nested_mosaic ,
1874
+ * _identify_keys_and_nested (nested_mosaic )
1875
1875
)
1876
1876
overlap = set (output ) & set (nested_output )
1877
1877
if overlap :
1878
1878
raise ValueError (
1879
1879
f"There are duplicate keys { overlap } "
1880
- f"between the outer layout\n { layout !r} \n "
1881
- f"and the nested layout\n { nested_layout } "
1880
+ f"between the outer layout\n { mosaic !r} \n "
1881
+ f"and the nested layout\n { nested_mosaic } "
1882
1882
)
1883
1883
output .update (nested_output )
1884
1884
else :
1885
1885
raise RuntimeError ("This should never happen" )
1886
1886
return output
1887
1887
1888
- layout = _make_array (layout )
1889
- rows , cols = layout .shape
1888
+ mosaic = _make_array (mosaic )
1889
+ rows , cols = mosaic .shape
1890
1890
gs = self .add_gridspec (rows , cols , ** gridspec_kw )
1891
- ret = _do_layout (gs , layout , * _identify_keys_and_nested (layout ))
1891
+ ret = _do_layout (gs , mosaic , * _identify_keys_and_nested (mosaic ))
1892
1892
ax0 = next (iter (ret .values ()))
1893
1893
for ax in ret .values ():
1894
1894
if sharex :
0 commit comments