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