spateo.plotting.static.align

Functions

slices_2d(slices[, slices_key, label_key, label_type, ...])

Plot multiple 2D spatial transcriptomics slices for both categorical clusters and scalar values.

overlay_slices_2d(slices[, slices_key, label_key, ...])

optimization_animation(aligned_slices[, label_key, ...])

plot_deformation_grid(adata, spatial_key, ...[, ...])

multi_slices(slices[, slices_key, label, spatial_key, ...])

_agenerate_palette(*labels[, cmap])

_compute_smallest_distance(spatial_coord1, spatial_coord2)

transform_by_min_max(x, _min, _max[, interval])

get_min_max(x)

transform_H(x, H[, z_shift])

get_H([h, w])

Module Contents

spateo.plotting.static.align.slices_2d(slices: anndata.AnnData | List[anndata.AnnData], slices_key: bool | str | None = None, label_key: str | None = None, label_type: str | None = None, spatial_key: str = 'spatial', point_size: float | None = None, n_sampling: int = -1, palette: dict | None = None, ncols: int = 4, title: str = '', title_kwargs: dict | None = None, show_legend: bool = True, legend_kwargs: dict | None = None, axis_off: bool = False, axis_kwargs: dict | None = None, ticks_off: bool = True, x_min=None, x_max=None, y_min=None, y_max=None, height: float = 2, alpha: float = 1.0, cmap='tab20', center_coordinate: bool = False, gridspec_kws: dict | None = None, return_palette: bool = False, save_show_or_return: Literal['save', 'show', 'return', 'both', 'all'] = 'show', save_kwargs: dict | None = None, sort_values: bool = True, sort_ascending: bool = True, **kwargs)[source]

Plot multiple 2D spatial transcriptomics slices for both categorical clusters and scalar values.

Parameters:
slices

A single AnnData object or a list of AnnData, each element represents one spatial slice.

slices_key

Column in .obs that identifies each slice. Required when a single AnnData containing multiple batches is supplied.

label_key

Column name in .obs or gene name in .var whose values will be visualised. If the value is numeric, it will be treated as a scalar value, otherwise it will be treated as a cluster.

label_type

Force interpretation of label_key as 'cluster' or 'scalar'. If None the type is inferred automatically. If the value is numeric, it will be treated as a scalar value, otherwise it will be treated as a cluster.

spatial_key

Key in .obsm that stores the spatial coordinates (default 'spatial').

point_size

Size of scatter points in points². If None an empirical value is computed based on the overall point density.

n_sampling

Down-sample each slice to n_sampling points (without replacement). Supply -1 to disable down-sampling.

palette

Mapping from category → color for cluster plots or a colormap name for scalar plots. If None a palette/colormap is generated automatically.

ncols

Number of subplot columns. The value is automatically clipped so as not to exceed the number of slices.

title

Common title string and optional Axes.set_title keyword arguments.

title_kwargs

Common title string and optional Axes.set_title keyword arguments.

show_legend

Whether to draw a legend (clusters) or colour-bar (scalar) and optional keyword overrides.

legend_kwargs

Whether to draw a legend (clusters) or colour-bar (scalar) and optional keyword overrides.

axis_off

Whether to hide the axis frame/ticks and optional overrides to Axes.axis.

axis_kwargs

Whether to hide the axis frame/ticks and optional overrides to Axes.axis.

ticks_off

If True x/y-tick labels are removed.

x_min

Explicit axis limits. When None the limits are derived from the data and padded by 5 % so that points at the border are still visible.

x_max

Explicit axis limits. When None the limits are derived from the data and padded by 5 % so that points at the border are still visible.

y_min

Explicit axis limits. When None the limits are derived from the data and padded by 5 % so that points at the border are still visible.

y_max

Explicit axis limits. When None the limits are derived from the data and padded by 5 % so that points at the border are still visible.

height

Height of one subplot in inches.

alpha

Global alpha (transparency) for all points.

cmap

Name of a matplotlib colormap to use when label_type == 'scalar'.

center_coordinate

If True centre the coordinates of every slice at (0, 0).

gridspec_kws

Extra keyword arguments passed to plt.subplots via the gridspec_kw parameter.

return_palette

If True the colour mapping used for plotting is returned alongside the figure.

save_show_or_return

One of 'save', 'show', 'return' or 'both' / 'all' – forwarded to save_return_show_fig_utils().

save_kwargs

Extra keyword arguments for saving.

sort_values

Only relevant for scalar plots. If True the points are rendered in order of label_key (after sorting) so that points with higher (or lower) values are drawn on top.

sort_ascending

Sort direction used when sort_values is True (ascending ⇢ smaller values on top).

**kwargs

Additional keyword arguments forwarded to matplotlib.pyplot.scatter().

Returns:

  • Depending on save_show_or_return either a matplotlib.figure.Figure

  • object, None (when the figure is saved/shown directly), or a tuple

  • containing both the figure and the palette.

spateo.plotting.static.align.overlay_slices_2d(slices: anndata.AnnData | List[anndata.AnnData], slices_key: bool | str | None = None, label_key: str | None = None, overlay_type: Literal['forward', 'backward', 'both'] = 'both', spatial_key: str = 'spatial', point_size: float | None = None, n_sampling: int = -1, palette: dict | None = None, ncols: int = 4, title: str = '', title_kwargs: dict | None = None, show_legend: bool = True, legend_kwargs: dict | None = None, axis_off: bool = False, axis_kwargs: dict | None = None, ticks_off: bool = True, x_min=None, x_max=None, y_min=None, y_max=None, height: float = 2, alpha: float = 1.0, cmap='tab20', center_coordinate: bool = False, gridspec_kws: dict | None = None, save_show_or_return: Literal['save', 'show', 'return', 'both', 'all'] = 'show', save_kwargs: dict | None = None, **kwargs)[source]
spateo.plotting.static.align.optimization_animation(aligned_slices: List[anndata.AnnData], label_key: str | None = None, spatial_key: str = 'spatial', key_added: str = 'align_spatial', iter_key_added: str | None = 'iter_spatial', filename: str | None = 'Visualization2D', fps: int = 10, stepsize: int = 10, cmap='Set1', palette: dict | None = None, point_size: float | None = None, n_sampling: int = -1)[source]
spateo.plotting.static.align.plot_deformation_grid(adata, spatial_key, origin_spatial_key, label_key, predict_func, ax, point_size, grid_num=10, line_width=0.5, grid_color='black', expand_scale=0.1, palette=None, title='', legend=True, fontsize=8, fill=False)[source]
spateo.plotting.static.align.multi_slices(slices: anndata.AnnData | List[anndata.AnnData], slices_key: str | None = None, label: str | None = None, spatial_key: str = 'align_spatial', layer: str = 'X', point_size: float | None = None, font_size: float | None = 20, color: str | None = 'skyblue', palette: str | None = None, alpha: float = 1.0, ncols: int = 4, ax_height: float = 1, dpi: int = 100, show_legend: bool = True, save_show_or_return: Literal['save', 'show', 'return', 'both', 'all'] = 'show', save_kwargs: dict | None = None, **kwargs)[source]
spateo.plotting.static.align._agenerate_palette(*labels, cmap='tab20')[source]
spateo.plotting.static.align._compute_smallest_distance(spatial_coord1, spatial_coord2, direction='x', scale_factor=1.1)[source]
spateo.plotting.static.align.transform_by_min_max(x, _min, _max, interval=0.1)[source]
spateo.plotting.static.align.get_min_max(x)[source]
spateo.plotting.static.align.transform_H(x, H, z_shift=0)[source]
spateo.plotting.static.align.get_H(h=0.5, w=0.2)[source]