MCPcopy Index your code
hub / github.com/pydata/xarray / _auto_grid

Function _auto_grid

xarray/plot/facetgrid.py:59–81  ·  view source on GitHub ↗
(
    nfacet: int, figsize: tuple[float, ...] | None, aspect: float
)

Source from the content-addressed store, hash-verified

57
58
59def _auto_grid(
60 nfacet: int, figsize: tuple[float, ...] | None, aspect: float
61) -> tuple[int, int]:
62
63 # Try to align the grid to the figsize. If figsize is unknown it gets
64 # computed from the grid, so lets keep it as square as possible
65 faspect = 1 if figsize is None else figsize[0] / figsize[1]
66
67 # Only wrap if > 3 images
68 if nfacet <= 3:
69 return nfacet, 1
70
71 # Geometric ideal case
72 ncol = int(np.ceil(np.sqrt(nfacet * faspect / aspect)))
73 ncol = max(1, min(ncol, nfacet))
74 nrow = int(np.ceil(nfacet / ncol))
75
76 # Reduce columns as long as we don't need more rows
77 # This eliminates empty slots in the last row if aspect < 1
78 while ncol > 1 and (ncol - 1) * nrow >= nfacet:
79 ncol -= 1
80
81 return ncol, nrow
82
83
84T_FacetGrid = TypeVar("T_FacetGrid", bound="FacetGrid")

Callers 1

__init__Method · 0.85

Calls 1

ceilMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…