spatials#
API pages include interactive (HTML) plots that would possibly not render correctly on a mobile device.
- spatials(data: AnnData | SpatialData, keys: Sequence[str], *, library_id: str | None = None, image: bool = True, image_key: Literal['hires', 'lowres'] | str = 'lowres', greyscale: bool = False, image_alpha: float | None = None, cmap: str | list | None = None, norm: bool | None = None, vmin: float | None = None, vmax: float | None = None, scale_axis: Literal[0, 1] | None = None, spatial_key: str = 'spatial', table_name: str | None = None, image_name: str | None = None, shapes_name: str | None = None, coordinate_system: str | None = None, polygon: bool = False, crop: Sequence[int] | None = None, mapping: FeatureSpec | None = None, size: float | None = 1.5, alpha: float = 1.0, groups: Sequence[str] | str | None = None, drop: Sequence[str] | str | None = None, variable_keys: Sequence[str] | str | None = None, add_columns: Sequence[str] | str | None = None, include_dimensions: bool | int = False, tooltips: Literal['none'] | Sequence[str] | FeatureSpec | None = None, interactive: bool = False, observations_name: str = 'Barcode', color_low: str = '#f6f6f6', color_mid: str | None = None, color_high: str = '#377eb8', mid_point: Literal['mean', 'median', 'mid'] | float = 'mid', share_labels: bool = False, layers: Sequence[FeatureSpec | LayerSpec] | FeatureSpec | LayerSpec | None = None, ncol: int | None = None, sharex: str | None = None, sharey: str | None = None, widths: list[float] | None = None, heights: list[float] | None = None, hspace: float | None = None, vspace: float | None = None, fit: bool | None = None, align: bool | None = None, guides: str = 'auto', **point_kwargs) SupPlotsSpec#
Grid of spatial plots.
- Parameters:
data (
AnnData | SpatialData) – Spatial data to plot. AnnData inputs use Visium-style metadata stored on the object. SpatialData inputs are resolved via the table_name, image_name, shapes_name, and coordinate_system arguments below.keys (
Sequence[str]) – The keys (cell features or gene names) to color the spots by.library_id (
str | None, defaultNone) – The library identifier. If None and only one library is present, it is auto-selected; if multiple libraries are present, this must be provided. Leave as None when no library metadata is present (generic spatial data). Ignored for SpatialData inputs.image (
bool, defaultTrue) – Whether to render the tissue image as a background layer.image_key (
str, default'lowres') – Which image variant to render. Visium ships with ‘hires’ and ‘lowres’. Falls back to ‘hires’, then to any available variant, when the requested one is missing. Ignored for SpatialData inputs.greyscale (
bool, defaultFalse) – Whether to convert an RGB(A) image to greyscale (Rec.709 luminance).image_alpha (
float | None, defaultNone) – Alpha (transparency) of the tissue image. Distinct from alpha, which controls spot transparency.cmap (
str | list | None, defaultNone) – Colormap name or list of colors. Greyscale images only.norm (
bool | None, defaultNone) – Whether to linearly scale greyscale luminance values to [0, 255]. Greyscale images only.vmin (
float | None, defaultNone) – Lower bound for greyscale luminance normalization.vmax (
float | None, defaultNone) – Upper bound for greyscale luminance normalization.scale_axis (
{0, 1}| None, defaultNone) – Whether to standardize key values between 0 and 1 (subtracts the minimum and divides by the maximum). Only applied when key is numeric.spatial_key (
str, default'spatial') – The embedding key containing spot coordinates in fullres pixel space. Ignored for SpatialData inputs.table_name (
str | None, defaultNone) – Selects which annotation table to use when multiple are present. If None and exactly one table is present, it is auto-selected. SpatialData inputs only.image_name (
str | None, defaultNone) – Selects which background image to render when multiple are present. If None and exactly one image is present, it is auto-selected. SpatialData inputs only.shapes_name (
str | None, defaultNone) – Selects which spot geometries to use when multiple are present. If None and exactly one geometry is present, it is auto-selected. SpatialData inputs only.coordinate_system (
str | None, defaultNone) – Target coordinate system. Image and geometries are aligned into this system before plotting. If None, the single available system is used, falling back to ‘global’ when multiple are defined. SpatialData inputs only.polygon (
bool, defaultFalse) – Render polygon-shaped geometries as filled polygons. When False (default), polygon geometries are reduced to their centroids and rendered as points. SpatialData inputs only.crop (
Sequence[int] | None, defaultNone) – Crop the plot to a region given as (left, right, top, bottom).mapping (
FeatureSpec | None, defaultNone) – Additional aesthetic mappings, the result of aes().size (
float | None, default0.8) – Spot size.alpha (
float, default1.0) – Alpha (transparency) of the spots.groups (
str | Sequence[str] | None, defaultNone) – Select specific groups to show.drop (
str | Sequence[str] | None, defaultNone) – Drop specific groups, filtering out rows where the key matches any of them. Categorical keys only.variable_keys (
str | Sequence[str] | None, defaultNone) – Variable keys to add to the DataFrame. If None, no additional keys are added.add_columns (
str | Sequence[str] | None, defaultNone) – Extra metadata columns or variable names to materialise into the shared frame, on top of those inferred from keys, mapping, and tooltips.include_dimensions (
bool | int) – Whether to include dimensions from embeddings in the DataFrame, default is False. Providing an integer will limit the number of dimensions to given number.tooltips (
{'none'}| Sequence[str] | FeatureSpec | None, defaultNone) – Tooltips to show when hovering over a spot. None auto-generates from mapped keys; ‘none’ disables tooltips.interactive (
bool, defaultFalse) – Whether to make the plot interactive.observations_name (
str, default'Barcode') – The name to give the barcode column in the DataFrame.color_low (
str, default'#f6f6f6') – Color for low values in the continuous gradient.color_mid (
str | None, defaultNone) – Color for mid values in the continuous gradient. When None, the scale falls back to a 2-color gradient between color_low and color_high.color_high (
str, default'#377eb8') – Color for high values in the continuous gradient.mid_point (
{'mean', 'median', 'mid'}| float, default'mid') – Midpoint for the continuous color gradient.share_labels (
bool, defaultFalse) – If True, only show axis labels at the grid edges.layers (
Sequence[FeatureSpec|LayerSpec] | FeatureSpec | LayerSpec | None, defaultNone) – Layers to add to every plot in the grid.ncol (
int, defaultNone) – Number of columns in grid. If None, plots are arranged in one row.sharex (
str | None, defaultNone) – Axis-sharing mode passed to gggrid.sharey (
str | None, defaultNone) – Axis-sharing mode passed to gggrid.widths (
list[float] | None, defaultNone) – Relative column widths / row heights.heights (
list[float] | None, defaultNone) – Relative column widths / row heights.hspace (
float | None, defaultNone) – Cell spacing in px.vspace (
float | None, defaultNone) – Cell spacing in px.fit (
bool | None, defaultNone) – Whether to stretch each plot to its cell.align (
bool | None, defaultNone) – Whether to align inner geom areas.guides (
str, default'auto') – How guides (legends, colorbars) are collected by gggrid.**point_kwargs – Additional parameters forwarded to geom_point.
- Returns:
SupPlotsSpec– Grid of spatial plots, one per key.
Notes
If no tissue image metadata is present, the plot falls back to a plain spatial scatter using the raw coordinates.
Examples
A grid of spatial plots with a sequnce of keys.
import scanpy as sc from lets_plot import * import cellestial as cl data = cl.datasets.human_lymph_node(cache_directory="data") cl.spatials(data,keys=["clusters","MS4A1"],interactive=True)
With another dataset.
import squidpy as sq data_hne = sq.datasets.visium_hne_adata() cl.spatials(data_hne,keys=["leiden","Mef2c"], interactive=True)
Adjust the layout via setting a column number.
cl.spatials(data_hne,keys=["leiden","Mef2c"], ncol=1, interactive=True) + ggsize(500,1000)