layout#

API pages include interactive (HTML) plots that would possibly not render correctly on a mobile device.

layout(plots: Sequence[Sequence[PlotSpec | SupPlotsSpec] | PlotSpec | SupPlotsSpec], *, widths: Sequence[float] | Sequence[Sequence[float]] | None = None, heights: Sequence[float] | None = None, hspace: float | None = None, vspace: float | None = None) → SupPlotsSpec#

Arrange plots into a grid of rows, where each inner list is one row.

Parameters:
  • plots (Sequence[Sequence[PlotSpec | SupPlotsSpec] | PlotSpec | SupPlotsSpec]) – A sequence of rows. Each element is either a sequence of plots or a single plot, which is treated as a one-plot row.

  • widths (Sequence[float] | Sequence[Sequence[float]] | None, default None) – Relative cell widths within each row. A nested sequence assigns widths per row (each inner length must match that row’s plot count). A flat sequence is broadcast to every row and is only valid when all rows have the same plot count. None distributes widths equally.

  • heights (Sequence[float] | None, default None) – Relative row heights, one value per row. None distributes heights equally.

  • hspace (float | None, default None) – Horizontal spacing between cells within a row, in pixels.

  • vspace (float | None, default None) – Vertical spacing between rows, in pixels.

Returns:

SupPlotsSpec – The composed grid.

Raises:
  • TypeError – If plots is not a nested sequence or widths is of an unexpected type.

  • ValueError – If any row is empty, or widths/heights lengths do not match the layout.

Notes

Unlike a uniform grid, rows may hold different numbers of plots. Each row is sized independently, so cells in different rows do not share column boundaries.

Examples

Arrange plots into ragged rows.

import scanpy as sc
from ggrust import *

import cellestial as cl

data = cl.datasets.pbmc3k()

first = cl.umap(data, key="CD14", axis_type="arrow")
second = cl.tsne(data, key="MALAT1", axis_type="arrow")
third = cl.umap(data, key="leiden", axis_type="arrow")

cl.layout(
    [[first, second],
     third],
    widths=[[1, 2], [1]],
    heights=[1, 1],
)
UMAP1 UMAP2 CD14 0 1 2 3 tSNE1 tSNE2 MALAT1 0 2 4 6 UMAP1 UMAP2 leiden 0 2 3 5 6 9 7 1 11 4 8 12 10 14 15 16 13 17 18 19 20 21 22 23 24 25 26