MCPcopy
hub / github.com/matplotlib/matplotlib / _do_layout

Method _do_layout

lib/matplotlib/figure.py:2101–2194  ·  view source on GitHub ↗

Recursively do the mosaic. Parameters ---------- gs : GridSpec mosaic : 2D object array The input converted to a 2D array for this level. unique_ids : tuple The identified scalar labels at this

(gs, mosaic, unique_ids, nested)

Source from the content-addressed store, hash-verified

2099 return tuple(unique_ids), nested
2100
2101 def _do_layout(gs, mosaic, unique_ids, nested):
2102 """
2103 Recursively do the mosaic.
2104
2105 Parameters
2106 ----------
2107 gs : GridSpec
2108 mosaic : 2D object array
2109 The input converted to a 2D array for this level.
2110 unique_ids : tuple
2111 The identified scalar labels at this level of nesting.
2112 nested : dict[tuple[int, int]], 2D object array
2113 The identified nested mosaics, if any.
2114
2115 Returns
2116 -------
2117 dict[label, Axes]
2118 A flat dict of all of the Axes created.
2119 """
2120 output = dict()
2121
2122 # we need to merge together the Axes at this level and the Axes
2123 # in the (recursively) nested sub-mosaics so that we can add
2124 # them to the figure in the "natural" order if you were to
2125 # ravel in c-order all of the Axes that will be created
2126 #
2127 # This will stash the upper left index of each object (axes or
2128 # nested mosaic) at this level
2129 this_level = dict()
2130
2131 # go through the unique keys,
2132 for name in unique_ids:
2133 # sort out where each axes starts/ends
2134 index = np.argwhere(mosaic == name)
2135 start_row, start_col = np.min(index, axis=0)
2136 end_row, end_col = np.max(index, axis=0) + 1
2137 # and construct the slice object
2138 slc = (slice(start_row, end_row), slice(start_col, end_col))
2139 # some light error checking
2140 if (mosaic[slc] != name).any():
2141 raise ValueError(
2142 f"While trying to layout\n{mosaic!r}\n"
2143 f"we found that the label {name!r} specifies a "
2144 "non-rectangular or non-contiguous area.")
2145 # and stash this slice for later
2146 this_level[(start_row, start_col)] = (name, slc, 'axes')
2147
2148 # do the same thing for the nested mosaics (simpler because these
2149 # cannot be spans yet!)
2150 for (j, k), nested_mosaic in nested.items():
2151 this_level[(j, k)] = (None, nested_mosaic, 'nested')
2152
2153 # now go through the things in this level and add them
2154 # in order left-to-right top-to-bottom
2155 for key in sorted(this_level):
2156 name, arg, method = this_level[key]
2157 # we are doing some hokey function dispatch here based
2158 # on the 'method' string stashed above to sort out if this

Callers

nothing calls this directly

Calls 6

add_subplotMethod · 0.95
minMethod · 0.80
maxMethod · 0.80
subgridspecMethod · 0.80
getMethod · 0.45
updateMethod · 0.45

Tested by

no test coverage detected