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