spateo.plotting.static#

Spatiotemporal modeling of spatial transcriptomics

Subpackages#

Submodules#

Package Contents#

Functions#

box_qc_regions(adata, layer, use_scale, box_kwargs, ...)

Indicate selected QC regions with boxes on the full tissue.

imshow(→ Optional[Tuple[matplotlib.figure.Figure, ...)

Display raw data within an AnnData.

qc_regions(→ Optional[Tuple[matplotlib.figure.Figure, ...)

Display QC regions.

multi_slices(slices, List[anndata.AnnData]], ...)

delaunay(edge_points, figsize, List] =, pc, title, ...)

Plot the Delaunay triangulation result.

polygon(concave_hull, shapely.geometry.Polygon], ...)

Plot the polygon identified by the alpha hull method.

color_label(adata[, basis, color_key, dpi, ...])

Color the segmented cells with different colors.

dotplot(adata, var_names, cat_key, Sequence[str]], ...)

Makes a dot plot of the expression values of var_names. For each var_name and each groupby category a dot

geo

Plotting functions for spatial geometry plots.

glm_fit(adata, genes, list]] = None, feature_x, ...)

Plot the glm_degs result in a scatterplot.

glm_heatmap(adata, genes, list]] = None, feature_x, ...)

Plot the glm_degs result in a heatmap.

ligrec(adata, dict_key, source_groups, str, ...)

Dotplot for visualizing results of ligand-receptor interaction analysis

plot_connections(adata, cat_key, spatial_key, ...)

Plot spatial_connections between labels- visualization of how closely labels are colocalized

lisa

lisa_quantiles(df)

Scatterplot of the gene expression and its spatial lag. Categorization into the four regions (HH, HL, LH, LL) is

polarity(adata, gene_dict, region_key[, mode])

Simple function to visualize expression level varies along regions.

scatters

space(adata[, color, genes, gene_cmaps, space, width, ...])

Scatter plot for physical coordinates of each cell.

acceleration(adata, model[, acceleration_key, ...])

Visualize the torsion result.

backbone(backbone_model[, backbone_key, ...])

Visualize constructed 3D backbone model.

curl(adata, model[, curl_key, filename, jupyter, ...])

Visualize the curl result.

curvature(adata, model[, curvature_key, filename, ...])

Visualize the curvature result.

deformation(*adata, deformed_grid[, layer, group_key, ...])

divergence(adata, model[, divergence_key, filename, ...])

Visualize the divergence result.

jacobian(adata, model[, jacobian_key, filename, ...])

Visualize the jacobian result.

merge_animations([mp4_files, mp4_folder, filename])

Use MoviePy to compose a new animation and play multiple animations together in the new animation.

multi_models(*adata[, layer, group_key, spatial_key, ...])

Visualize multiple models separately in one figure.

pairwise_iteration(adataA, adataB[, layer, group_key, ...])

Visualize the results of each iteration in the alignment process.

pairwise_mapping([idA, idB, adataA, adataB, pi, ...])

Visualize the pairing of cells between two models.

pi_heatmap(pi[, model1_name, model2_name, colormap, ...])

Visualize a heatmap of the pi matrix.

three_d_animate(models[, stable_model, stable_kwargs, ...])

Animated visualization of 3D reconstruction model.

three_d_multi_plot(model[, key, filename, jupyter, ...])

Multi-view visualization of reconstructed 3D model.

three_d_plot

torsion(adata, model[, torsion_key, filename, ...])

Visualize the torsion result.

spateo.plotting.static.box_qc_regions(adata: anndata.AnnData, layer: str = SKM.X_LAYER, use_scale: bool = True, box_kwargs: Optional[Dict] = None, ax: Optional[matplotlib.axes.Axes] = None, background: Optional[str] = None, save_show_or_return: typing_extensions.Literal[save, show, return, both, all] = 'show', save_kwargs: Optional[Dict] = None, **kwargs)[source]#

Indicate selected QC regions with boxes on the full tissue.

Parameters:
adata

Input Anndata

layer

Layer to display

use_scale

Whether or not to plot in physical units. Only valid when appropriate scale keys are present in .uns

box_kwargs

Keyword arguments to pass to patches.Rectangle(). By default, the boxes will be transparent with red outlines of 1 point thickness.

ax

Axes to plot.

background

string or None (optional, default ‘None`) The color of the background. Usually this will be either ‘white’ or ‘black’, but any color name will work. Ideally one wants to match this appropriately to the colors being used for points etc. This is one of the things that themes handle for you. Note that if theme is passed then this value will be overridden by the corresponding option of the theme.

save_show_or_return

Whether to save, show or return the figure. If “both”, it will save and plot the figure at the same time. If “all”, the figure will be saved, displayed and the associated axis and other object will be return.

save_kwargs

A dictionary that will passed to the save_fig function. By default it is an empty dictionary and the save_fig function will use the {“path”: None, “prefix”: ‘scatter’, “dpi”: None, “ext”: ‘pdf’, “transparent”: True, “close”: True, “verbose”: True} as its parameters. Otherwise you can provide a dictionary that properly modify those keys according to your needs.

**kwargs

Additional keyword arguments are all passed to imshow().

spateo.plotting.static.imshow(adata: anndata.AnnData, layer: str = SKM.X_LAYER, ax: Optional[matplotlib.axes.Axes] = None, show_cbar: bool = False, use_scale: bool = True, absolute: bool = False, labels: bool = False, downscale: float = 1.0, downscale_interpolation: Optional[int] = None, background: Optional[str] = None, save_show_or_return: typing_extensions.Literal[save, show, return, both, all] = 'show', save_kwargs: Optional[Dict] = None, **kwargs) Tuple[matplotlib.figure.Figure, matplotlib.axes.Axes] | None[source]#

Display raw data within an AnnData.

Parameters:
adata

Anndata containing aggregated UMI counts.

layer

Layer to display. Defaults to X.

ax

Axes to plot.

show_cbar

Whether or not to show a colorbar next to the plot.

use_scale

Whether or not to plot in physical units. Only valid when appropriate scale keys are present in .uns

absolute

Whether to set the axes to be in absolute coordinates. By default, relative coordinates are used (i.e. the axes start at zero).

labels

Whether the input data contains labels, encoded as positive integers.

downscale

Downscale image by this amount for faster plotting.

downscale_interpolation

Use this CV2 interpolation method when downscaling. By default, bilinear interpolation is used when labels=True and nearest neighbor interpolation when labels=False. Available options are located here: https://docs.opencv.org/3.4/da/d54/group__imgproc__transform.html#ga5bb5a1fea74ea38e1a5445ca803ff121 Only has an effect when downscale < 1.

background

string or None (optional, default ‘None`) The color of the background. Usually this will be either ‘white’ or ‘black’, but any color name will work. Ideally one wants to match this appropriately to the colors being used for points etc. This is one of the things that themes handle for you. Note that if theme is passed then this value will be overridden by the corresponding option of the theme.

save_show_or_return

Whether to save, show or return the figure. If “both”, it will save and plot the figure at the same time. If “all”, the figure will be saved, displayed and the associated axis and other object will be return.

save_kwargs

A dictionary that will passed to the save_fig function. By default it is an empty dictionary and the save_fig function will use the {“path”: None, “prefix”: ‘scatter’, “dpi”: None, “ext”: ‘pdf’, “transparent”: True, “close”: True, “verbose”: True} as its parameters. Otherwise you can provide a dictionary that properly modify those keys according to your needs.

**kwargs

Additional keyword arguments are all passed to imshow().

Returns:

The figure and axis if ax is not provided.

spateo.plotting.static.qc_regions(adata: anndata.AnnData, layer: str = SKM.X_LAYER, axes: Optional[numpy.ndarray] = None, ncols: int = 1, background: Optional[str] = None, save_show_or_return: typing_extensions.Literal[save, show, return, both, all] = 'show', save_kwargs: Optional[Dict] = None, **kwargs) Tuple[matplotlib.figure.Figure, numpy.ndarray] | None[source]#

Display QC regions.

Parameters:
adata

Input Anndata

layer

Layer to display

axes

Numpy array (possibly 2D) of Matplotlib axes to plot each region. This option is useful when trying to overlay multiple layers together.

ncols

Number of columns when displaying multiple panels.

background

string or None (optional, default ‘None`) The color of the background. Usually this will be either ‘white’ or ‘black’, but any color name will work. Ideally one wants to match this appropriately to the colors being used for points etc. This is one of the things that themes handle for you. Note that if theme is passed then this value will be overridden by the corresponding option of the theme.

save_show_or_return

Whether to save, show or return the figure. If “both”, it will save and plot the figure at the same time. If “all”, the figure will be saved, displayed and the associated axis and other object will be return.

save_kwargs

A dictionary that will passed to the save_fig function. By default it is an empty dictionary and the save_fig function will use the {“path”: None, “prefix”: ‘scatter’, “dpi”: None, “ext”: ‘pdf’, “transparent”: True, “close”: True, “verbose”: True} as its parameters. Otherwise you can provide a dictionary that properly modify those keys according to your needs.

**kwargs

Additional keyword arguments are all passed to imshow().

Returns:

The figure and axes if axes is not provided.

spateo.plotting.static.multi_slices(slices: Union[anndata.AnnData, List[anndata.AnnData]], slices_key: Optional[str] = None, label: Optional[str] = None, spatial_key: str = 'align_spatial', layer: str = 'X', point_size: Optional[float] = None, font_size: Optional[float] = 20, color: Optional[str] = 'skyblue', palette: Optional[str] = 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: Optional[dict] = None, **kwargs)[source]#
spateo.plotting.static.delaunay(edge_points, figsize: Union[Tuple, List] = (10, 10), pc: str = '#f16824', title: Optional[str] = None, fig: Optional[matplotlib.figure.Figure] = None, ax: Optional[matplotlib.axes.Axes] = None, background: Optional[str] = None, save_show_or_return: typing_extensions.Literal[save, show, return, both, all] = 'show', save_kwargs: Optional[Dict] = None)[source]#

Plot the Delaunay triangulation result.

Parameters:
edge_points

figsize

The size of the figure

fc

The color of the scatter points.

title

The title of the figure.

fig

The matplotlib.figure figure object of the figure.

ax

The matplotlib.axes._subplots AxesSubplot object of the figure.

background

string or None (optional, default ‘None`) The color of the background. Usually this will be either ‘white’ or ‘black’, but any color name will work. Ideally one wants to match this appropriately to the colors being used for points etc. This is one of the things that themes handle for you. Note that if theme is passed then this value will be overridden by the corresponding option of the theme.

save_show_or_return

Whether to save, show or return the figure. If “both”, it will save and plot the figure at the same time. If “all”, the figure will be saved, displayed and the associated axis and other object will be return.

save_kwargs

A dictionary that will passed to the save_fig function. By default it is an empty dictionary and the save_fig function will use the {“path”: None, “prefix”: ‘scatter’, “dpi”: None, “ext”: ‘pdf’, “transparent”: True, “close”: True, “verbose”: True} as its parameters. Otherwise you can provide a dictionary that properly modify those keys according to your needs.

Returns:

The matplotlib.figure figure object of the figure. ax: The matplotlib.axes._subplots AxesSubplot object of the figure.

Return type:

fig

spateo.plotting.static.polygon(concave_hull: Union[shapely.geometry.MultiPolygon, shapely.geometry.Polygon], figsize: Union[Tuple, List] = (10, 10), margin: float = 0.3, fc: str = '#999999', ec: str = '#000000', fig: Optional[matplotlib.figure.Figure] = None, ax: Optional[matplotlib.axes.Axes] = None, background: Optional[str] = None, save_show_or_return: typing_extensions.Literal[save, show, return, both, all] = 'show', save_kwargs: Optional[Dict] = None)[source]#

Plot the polygon identified by the alpha hull method.

Parameters:
concave_hull

The identified polygon (or multi-polygon) returned from the alpha_shape method or other methods.

figsize

The size of the figure

margin

The margin of the figure Axes.

fc

The facecolor of the PolygonPatch.

ec

The edgecolor of the PolygonPatch.

background

string or None (optional, default ‘None`) The color of the background. Usually this will be either ‘white’ or ‘black’, but any color name will work. Ideally one wants to match this appropriately to the colors being used for points etc. This is one of the things that themes handle for you. Note that if theme is passed then this value will be overridden by the corresponding option of the theme.

save_show_or_return

Whether to save, show or return the figure. If “both”, it will save and plot the figure at the same time. If “all”, the figure will be saved, displayed and the associated axis and other object will be return.

save_kwargs

A dictionary that will passed to the save_fig function. By default it is an empty dictionary and the save_fig function will use the {“path”: None, “prefix”: ‘scatter’, “dpi”: None, “ext”: ‘pdf’, “transparent”: True, “close”: True, “verbose”: True} as its parameters. Otherwise you can provide a dictionary that properly modify those keys according to your needs.

Returns:

The matplotlib.figure figure object of the figure. ax: The matplotlib.axes._subplots AxesSubplot object of the figure.

Return type:

fig

spateo.plotting.static.color_label(adata: anndata.AnnData, basis='contour', color_key: list | None = None, dpi: int = 100, boundary_width: float = 0.2, boundary_color='black', figsize=(6, 6), aspect: str = 'equal', *args, **kwargs)[source]#

Color the segmented cells with different colors.

Parameters:
adata

~anndata.AnnData An Annodata object.

basis

str The key to the column in the adata.obs, from which the contour of the cell segmentation will be generated.

color_key

list List of colors. If the number of labels exceeds the number of colors, then the colors are cycled.

dpi

float, (default: 100.0) The resolution of the figure in dots-per-inch. Dots per inches (dpi) determines how many pixels the figure comprises. dpi is different from ppi or points per inches. Note that most elements like lines, markers, texts have a size given in points so you can convert the points to inches. Matplotlib figures use Points per inch (ppi) of 72. A line with thickness 1 point will be 1./72. inch wide. A text with fontsize 12 points will be 12./72. inch height. Of course if you change the figure size in inches, points will not change, so a larger figure in inches still has the same size of the elements.Changing the figure size is thus like taking a piece of paper of a different size. Doing so, would of course not change the width of the line drawn with the same pen. On the other hand, changing the dpi scales those elements. At 72 dpi, a line of 1 point size is one pixel strong. At 144 dpi, this line is 2 pixels strong. A larger dpi will therefore act like a magnifying glass. All elements are scaled by the magnifying power of the lens. see more details at answer 2 by @ImportanceOfBeingErnest: https://stackoverflow.com/questions/47633546/relationship-between-dpi-and-figure-size

boundary_width

float, (default: 0.2) The line width of boundary.

boundary_color

(default: “black”) The color value of boundary.

figsize

tuple The size of the figure in inches.

aspect

str Set the aspect of the axis scaling, i.e. the ratio of y-unit to x-unit. In physical spatial plot, the default is ‘equal’. See more details at: https://matplotlib.org/stable/api/_as_gen/matplotlib.axes.Axes.set_aspect.html

spateo.plotting.static.dotplot(adata: anndata.AnnData, var_names: Sequence[str], cat_key: Union[str, Sequence[str]], num_categories: int = 7, cell_cell_dp: bool = False, delta: Union[None, float] = None, minn: Union[None, float] = None, alpha: Union[None, float] = None, prescale_adata: bool = False, expression_cutoff: float = 0.0, mean_only_expressed: bool = False, cmap: str = 'Reds', dot_max: float = Dotplot.default_dot_max, dot_min: float = Dotplot.default_dot_min, standard_scale: Literal[var, group] = None, smallest_dot: float = Dotplot.default_smallest_dot, largest_dot: float = Dotplot.default_largest_dot, title: str = None, colorbar_title: str = Dotplot.default_color_legend_title, size_title: str = Dotplot.default_size_legend_title, figsize: Union[None, Tuple[float, float]] = None, dendrogram: Union[bool, str] = False, gene_symbols_key: Union[None, str] = None, var_group_positions: Union[None, Sequence[Tuple[int, int]]] = None, var_group_labels: Union[None, Sequence[str]] = None, var_group_rotation: Union[None, float] = None, layer: Union[None, str] = None, swap_axes: bool = False, dot_color_df: Union[None, pandas.DataFrame] = None, save_show_or_return: Literal[save, show, return, both, all] = 'save', save_kwargs: dict = {}, ax: Union[None, matplotlib.axes.Axes] = None, vmin: Union[None, float] = None, vmax: Union[None, float] = None, vcenter: Union[None, float] = None, norm: Union[None, matplotlib.colors.Normalize] = None, **kwargs)[source]#

Makes a dot plot of the expression values of var_names. For each var_name and each groupby category a dot is plotted. Each dot represents two values: mean expression within each category (visualized by color) and fraction of cells expressing the var_name in the category (visualized by the size of the dot). If groupby is not given, the dotplot assumes that all data belongs to a single category.

Parameters:
adata

object of class anndata.AnnData

var_names

Should be a subset of adata.var_names

cat_key

The key(s) in .obs of the grouping to consider. Should be a categorical observation; if not, will be subdivided into ‘num_categories’.

num_categories

Only used if groupby observation is not categorical. This value determines the number of groups into which the groupby observation should be subdivided.

cell_cell_dp

Set True to initialize specialized cell-cell dotplot instead of gene expression dotplot

delta

Only used if ‘cell_cell_dp’ is True- distance between the largest value to consider and the smallest value to consider (see ‘minn’ parameter below)

minn

Only used if ‘cell_cell_dp’ is True- for the dot size legend, sets the value corresponding to the smallest dot on the legend

alpha

Only used if ‘cell_cell_dp’ is True- significance threshold. If given, all elements w/ p-values <= ‘alpha’ will be marked by rings instead of dots.

prescale_adata

Set True to indicate that AnnData object should be scaled- if so, will use ‘delta’ and ‘minn’ to do so. If False, will proceed as though adata has already been processed as needed.

expression_cutoff

Used for binarizing feature expression- feature is considered to be expressed only if the expression value is greater than this threshold

mean_only_expressed

If True, gene expression is averaged only over the cells expressing the given features

cmap

Name of Matplotlib color map to use

dot_max

If none, the maximum dot size is set to the maximum fraction value found (e.g. 0.6). If given, the value should be a number between 0 and 1. All fractions larger than dot_max are clipped to this value.

dot_min

If none, the minimum dot size is set to 0. If given, the value should be a number between 0 and 1. All fractions smaller than dot_min are clipped to this value.

standard_scale

Whether or not to standardize that dimension between 0 and 1, meaning for each variable or group, subtract the minimum and divide each by its maximum. ‘val’ or ‘group’ is used to specify whether this should be done over variables or groups.

smallest_dot

If None, the smallest dot has size 0. All expression fractions with dot_min are plotted with this size.

largest_dot

If None, the largest dot has size 200. All expression fractions with dot_max are plotted with this size.

title

Title for the entire plot

colorbar_title

Title for the color legend. If None will use generic default title

size_title

Title for the dot size legend. If None will use generic default title

figsize

Sets width and height of figure window

dendrogram

If True, adds dendrogram to plot. Will do the same thing if string is given here, but will recompute dendrogram and save using this argument to set key in .uns.

gene_symbols_key

Key in .var containing gene symbols

var_group_positions

Each item in the list should contain the start and end position that the bracket should cover. Eg. [(0, 4), (5, 8)] means that there are two brackets, one for the var_names in positions 0-4 and other for positions 5-8

var_group_labels

List of group labels for the variable names (e.g. can group var_names in positions 0-4 as being “group A”)

var_group_rotation

Rotation in degrees of the variable name labels. If not given, small labels (<4 characters) are not rotated, but otherwise labels are rotated 90 degrees.

layer

Key in .layers specifying layer to use. If not given, will use .X.

swap_axes

Set True to switch what is plotted on the x- and y-axes

dot_color_df

Pre-prepared dataframe with features as indices, categories as columns, and indices corresponding to color intensities

save_show_or_return

Options: “save”, “show”, “return”, “both”, “all” - “both” for save and show

save_kwargs

A dictionary that will passed to the save_fig function. By default it is an empty dictionary and the save_fig function will use the {“path”: None, “prefix”: ‘scatter’, “dpi”: None, “ext”: ‘pdf’, “transparent”: True, “close”: True, “verbose”: True} as its parameters. But to change any of these parameters, this dictionary can be used to do so.

ax

Pre-initialized axis object to plot on

vmin

The data value that defines 0.0 in the normalization. Defaults to the min value of the dataset.

vmax

The data value that defines 1.0 in the normalization. Defaults to the the max value of the dataset.

vcenter

The data value that defines 0.5 in the normalization

norm

Optional already-initialized normalizing object that scales data, typically into the interval [0, 1], for the purposes of mapping to color intensities for plotting. Do not pass both ‘norm’ and ‘vmin’/’vmax’, etc.

kwargs

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

Returns:

Instantiated Figure object- only if ‘return’ is True axes: Instantiated Axes object- only if ‘return’ is True

Return type:

fig

spateo.plotting.static.geo(adata: anndata.AnnData, basis: str = 'contour', color: list | str | None = None, genes: list | None = [], gene_cmaps: str | None = None, dpi: int = 100, alpha: float = 0.8, boundary_width: float = 0.2, boundary_color='black', stack_genes: bool = False, stack_genes_threshold: float = 0.01, stack_colors_legend_size: int = 10, figsize: Tuple[float, float] = (6, 6), aspect: str = 'equal', slices: int | None = None, img_layers: int | None = None, *args, **kwargs)#

Geometry plot for physical coordinates of each cell.

Parameters:
adata

an Annodata object that contain the physical coordinates for each bin/cell, etc.

basis

The key to the column in adata.obs from which the contour of the cell segmentation will be generated.

color

Any or any list of column names or gene name, etc. that will be used for coloring cells. If color is not None, stack_genes will be disabled automatically because color can contain non numerical values.

genes

The gene list that will be used to plot the gene expression on the same scatter plot. Each gene will have a different color. Can be a single gene name string and we will convert it to a list.

gene_cmaps

The colormap used to stack different genes in a single plot.

dpi

The resolution of the figure in dots-per-inch. Dots per inches (dpi) determines how many pixels the figure comprises. dpi is different from ppi or points per inches. Note that most elements like lines, markers, texts have a size given in points so you can convert the points to inches. Matplotlib figures use Points per inch (ppi) of 72. A line with thickness 1 point will be 1./72. inch wide. A text with fontsize 12 points will be 12./72. inch height. Of course if you change the figure size in inches, points will not change, so a larger figure in inches still has the same size of the elements.Changing the figure size is thus like taking a piece of paper of a different size. Doing so, would of course not change the width of the line drawn with the same pen. On the other hand, changing the dpi scales those elements. At 72 dpi, a line of 1 point size is one pixel strong. At 144 dpi, this line is 2 pixels strong. A larger dpi will therefore act like a magnifying glass. All elements are scaled by the magnifying power of the lens. see more details at answer 2 by @ImportanceOfBeingErnest: https://stackoverflow.com/questions/47633546/relationship-between-dpi-and-figure-size

alpha

The alpha value of the cells.

boundary_width

The line width of boundary.

boundary_color

The color value of boundary.

stack_genes

whether to show all gene plots on the same plot

stack_genes_threshold

lower bound of gene values that will be drawn on the plot.

stack_colors_legend_size

control the size of legend when stacking genes

figuresize

size of the figure.

aspect

Set the aspect of the axis scaling, i.e. the ratio of y-unit to x-unit. In physical spatial plot, the default is ‘equal’. See more details at: https://matplotlib.org/stable/api/_as_gen/matplotlib.axes.Axes.set_aspect.html

slices

The index to the tissue slice, will used in adata.uns[“spatial”][slices].

img_layers

The index to the (staining) image of a tissue slice, will be used in adata.uns[“spatial”][slices][“images”].

Return type:

plots gene or cell feature of the adata object on the physical spatial coordinates.

spateo.plotting.static.glm_fit(adata: anndata.AnnData, genes: Optional[Union[str, list]] = None, feature_x: str = None, feature_y: str = 'expression', glm_key: str = 'glm_degs', remove_zero: bool = False, color_key: Optional[str] = None, color_key_cmap: Optional[str] = 'vlag', point_size: float = 14, point_color: Union[str, numpy.ndarray, list] = 'skyblue', line_size: float = 2, line_color: str = 'black', ax_size: Union[tuple, list] = (6, 4), background_color: str = 'white', ncols: int = 4, show_point: bool = True, show_line: bool = True, show_legend: bool = True, save_show_or_return: Literal[save, show, return, both, all] = 'show', save_kwargs: Optional[dict] = None, **kwargs)[source]#

Plot the glm_degs result in a scatterplot.

Parameters:
adata

An Anndata object contain glm_degs result in .uns[glm_key].

genes

A gene name or a list of genes that will be used to plot.

feature_x

The key in .uns[glm_key]['correlation'][gene] that corresponds to the independent variables, such as 'torsion', etc.

feature_y

The key in .uns[glm_key]['correlation'][gene] that corresponds to the dependent variables, such as 'expression', etc.

glm_key

The key in .uns that corresponds to the glm_degs result.

remove_zero

Whether to remove the data equal to 0 saved in .uns[glm_key]['correlation'][gene][feature_y].

color_key

This can either be an explicit dict mapping labels to colors (as strings of form ‘#RRGGBB’), or an array like object providing one color for each distinct category being provided in labels.

color_key_cmap

The name of a matplotlib colormap to use for categorical coloring.

point_size

The scale of the feature_y point size.

point_color

The color of the feature_y point.

line_size

The scale of the fitted line width.

line_color

The color of the fitted line.

ax_size

The width and height of each ax.

background_color

The background color of the figure.

ncols

Number of columns for the figure.

show_point

Whether to show the scatter plot.

show_line

Whether to show the line plot.

show_legend

Whether to show the legend.

save_show_or_return

If 'both', it will save and plot the figure at the same time.

If 'all', the figure will be saved, displayed and the associated axis and other object will be return.

save_kwargs

A dictionary that will be passed to the save_fig function.

By default, it is an empty dictionary and the save_fig function will use the {"path": None, "prefix": 'scatter', "dpi": None, "ext": 'pdf', "transparent": True, "close": True, "verbose": True} as its parameters.

Otherwise, you can provide a dictionary that properly modify those keys according to your needs.

**kwargs

Additional parameters that will be passed into the seaborn.scatterplot function.

spateo.plotting.static.glm_heatmap(adata: anndata.AnnData, genes: Optional[Union[str, list]] = None, feature_x: str = None, feature_y: str = 'expression', glm_key: str = 'glm_degs', lowess_smooth: bool = True, frac: float = 0.2, robust: bool = True, colormap: str = 'vlag', figsize: tuple = (6, 6), background_color: str = 'white', show_legend: bool = True, save_show_or_return: Literal[save, show, return, both, all] = 'show', save_kwargs: Optional[dict] = None, **kwargs)[source]#

Plot the glm_degs result in a heatmap.

Parameters:
adata

An Anndata object contain glm_degs result in .uns[glm_key].

genes

A gene name or a list of genes that will be used to plot.

feature_x

The key in .uns[glm_key]['correlation'][gene] that corresponds to the independent variables, such as 'torsion', etc.

feature_y

The key in .uns[glm_key]['correlation'][gene] that corresponds to the dependent variables, such as 'expression', etc.

glm_key

The key in .uns that corresponds to the glm_degs result.

lowess_smooth

If True, use statsmodels to estimate a nonparametric lowess model (locally weighted linear regression).

frac

Between 0 and 1. The fraction of the data used when estimating each y-value.

robust

If True and vmin or vmax are absent, the colormap range is computed with robust quantiles instead of the extreme values.

colormap

The name of a matplotlib colormap.

figsize

The width and height of figure.

background_color

The background color of the figure.

show_legend

Whether to show the legend.

save_show_or_return

If 'both', it will save and plot the figure at the same time.

If 'all', the figure will be saved, displayed and the associated axis and other object will be return.

save_kwargs

A dictionary that will be passed to the save_fig function.

By default, it is an empty dictionary and the save_fig function will use the {"path": None, "prefix": 'scatter', "dpi": None, "ext": 'pdf', "transparent": True, "close": True, "verbose": True} as its parameters.

Otherwise, you can provide a dictionary that properly modify those keys according to your needs.

**kwargs

Additional parameters that will be passed into the seaborn.heatmap function.

spateo.plotting.static.ligrec(adata: anndata.AnnData, dict_key: str, source_groups: Union[None, str, List[str]] = None, target_groups: Union[None, str, List[str]] = None, means_range: Tuple[float, float] = (-np.inf, np.inf), pvalue_threshold: float = 1.0, remove_empty_interactions: bool = True, remove_nonsig_interactions: bool = False, dendrogram: Union[None, str] = None, alpha: float = 0.001, swap_axes: bool = False, title: Union[None, str] = None, figsize: Union[None, Tuple[float, float]] = None, save_show_or_return: Literal[save, show, return, both, all] = 'show', save_kwargs: Optional[ligrec.dict] = {}, **kwargs)[source]#

Dotplot for visualizing results of ligand-receptor interaction analysis

For each L:R pair on the dotplot, molecule 1 is sent from the cluster(s) labeled on the top of the plot (or on the right, if ‘swap_axes’ is True), whereas molecule 2 is the receptor on the cluster(s) labeled on the bottom.

Parameters:
adata

Object of :class anndata.AnnData

dict_key

Key in .uns to dictionary containing cell-cell communication information. Should contain keys labeled “means” and “pvalues”, with values being dataframes for the mean cell type-cell type L:R product and significance values.

source_groups

Source interaction clusters. If None, select all clusters.

target_groups

Target interaction clusters. If None, select all clusters.

means_range

Only show interactions whose means are within this closed interval

pvalue_threshold

Only show interactions with p-value <= pvalue_threshold

remove_empty_interactions

Remove rows and columns that contain NaN values

remove_nonsig_interactions

Remove rows and columns that only contain interactions that are larger than alpha

dendrogram

How to cluster based on the p-values. Valid options are: - None (no input) - do not perform clustering. - ‘interacting_molecules’ - cluster the interacting molecules. - ‘interacting_clusters’ - cluster the interacting clusters. - ‘both’ - cluster both rows and columns. Note that in this case, the dendrogram is not shown.

alpha

Significance threshold. All elements with p-values <= alpha will be marked by tori instead of dots.

swap_axes

Whether to show the cluster combinations as rows and the interacting pairs as columns

title

Title of the plot

figsize

The width and height of a figure

save_show_or_return

Options: “save”, “show”, “return”, “both”, “all” - “both” for save and show

save_kwargs

A dictionary that will passed to the save_fig function. By default it is an empty dictionary and the save_fig function will use the {“path”: None, “prefix”: ‘scatter’, “dpi”: None, “ext”: ‘pdf’, “transparent”: True, “close”: True, “verbose”: True} as its parameters. But to change any of these parameters, this dictionary can be used to do so.

kwargs

Keyword arguments for :func style or :func legend of :class Dotplot

spateo.plotting.static.plot_connections(adata: anndata.AnnData, cat_key: str, spatial_key: str = 'spatial', n_spatial_neighbors: Union[None, int] = 6, spatial_weights_matrix: Union[None, scipy.sparse.csr_matrix, numpy.ndarray] = None, expr_weights_matrix: Union[None, scipy.sparse.csr_matrix, numpy.ndarray] = None, reverse_expr_plot_orientation: bool = True, ax: Union[None, matplotlib.axes.Axes] = None, figsize: tuple = (3, 3), zero_self_connections: bool = True, normalize_by_self_connections: bool = False, shapes_style: bool = True, label_outline: bool = False, max_scale: float = 0.46, colormap: Union[str, dict, matplotlib.colormap] = 'Spectral', title_str: Union[None, str] = None, title_fontsize: Union[None, float] = None, label_fontsize: Union[None, float] = None, save_show_or_return: Literal[save, show, return, both, all] = 'show', save_kwargs: Optional[dict] = {})[source]#

Plot spatial_connections between labels- visualization of how closely labels are colocalized

Parameters:
adata

AnnData object

cat_key

Key in .obs containing categorical grouping labels. Colocalization will be assessed for pairwise combinations of these labels.

spatial_key

Key in .obsm containing coordinates in the physical space. Not used unless ‘spatial_weights_matrix’ is None, in which case this is required. Defaults to “spatial”.

n_spatial_neighbors

Optional, number of neighbors in the physical space for each cell. Not used unless ‘spatial_weights_matrix’ is None.

spatial_weights_matrix

Spatial distance matrix, weighted by distance between spots. If not given, will compute at runtime.

expr_weights_matrix

Gene expression distance matrix, weighted by distance in transcriptomic or PCA space. If not given, only the spatial distance matrix will be plotted. If given, will plot the spatial distance matrix in the left plot and the gene expression distance matrix in the right plot.

reverse_expr_plot_orientation

If True, plot the gene expression connections in the form of a lower right triangle. If False, gene expression connections will be an upper left triangle just like the spatial connections.

ax

Existing axes object, if applicable

figsize

Width x height of desired figure window in inches

zero_self_connections

If True, ignores intra-label interactions

normalize_by_self_connections

Only used if ‘zero_self_connections’ is False. If True, normalize intra-label connections by the number of spots of that label

shapes_style

If True plots squares, if False plots heatmap

label_outline

If True, gives dark outline to axis tick label text

max_scale

Only used for the case that ‘shape_style’ is True, gives maximum size of square

colormap

Specifies colors to use for plotting. If dictionary, keys should be numerical labels corresponding to those of the Label object.

title_str

Optionally used to give plot a title

title_fontsize

Size of plot title- only used if ‘title_str’ is given.

label_fontsize

Size of labels along the axes of the graph

save_show_or_return

Whether to save, show or return the figure. If “both”, it will save and plot the figure at the same time. If “all”, the figure will be saved, displayed and the associated axis and other object will be return.

save_kwargs

A dictionary that will passed to the save_fig function. By default it is an empty dictionary and the save_fig function will use the {“path”: None, “prefix”: ‘scatter’, “dpi”: None, “ext”: ‘pdf’, “transparent”: True, “close”: True, “verbose”: True} as its parameters. Otherwise you can provide a dictionary that properly modifies those keys according to your needs.

Returns:

Returns plot and axis object if ‘save_show_or_return’ is “all”

Return type:

(fig, ax)

spateo.plotting.static.lisa(df: geopandas.GeoDataFrame)#

Create a plot with four panels. The first one is for the raw lisa (Local Indicators of Spatial Association ) score. The second one (the right one in the first row) is for the four quantiles. The third one is for the significance while the fourth one the five categories (not significant, hotspot, doughnut, coldspot and diamond.

Parameters:
df

The GeoDataFrame returned from running st.tl.lisa_geo_df(adata, gene).

Returns:

Nothing but plot the four panels .

spateo.plotting.static.lisa_quantiles(df: geopandas.GeoDataFrame)[source]#

Scatterplot of the gene expression and its spatial lag. Categorization into the four regions (HH, HL, LH, LL) is also annotated. This function should be used in conjunction with st.tl.lisa_geo_df.

Parameters:
df

The GeoDataFrame returned from running st.tl.lisa_geo_df(adata, gene).

Returns:

Nothing but plot the scatterplot.

spateo.plotting.static.polarity(adata: anndata.AnnData, gene_dict: dict, region_key: str, mode: str = 'density')[source]#

Simple function to visualize expression level varies along regions.

Parameters:
adata AnnData

_description_

gene_dict dict

_description_

region_key str

_description_

mode str, optional

_description_. Defaults to “density”.

Returns:

_description_

Return type:

_type_

spateo.plotting.static.scatters(adata: anndata.AnnData, basis: Union[str, list] = 'umap', vf_key: Optional[str] = None, X_grid: Optional[numpy.ndarray] = None, V: Optional[numpy.ndarray] = None, x: int = 0, y: int = 1, z: int = 2, color: Union[str, list] = 'ntr', layer: Union[str, list] = 'X', highlights: Optional[list] = None, labels: Optional[list] = None, values: Optional[list] = None, theme: Optional[str] = None, cmap: Optional[str] = None, color_key: Union[dict, list] = None, color_key_cmap: Optional[str] = None, background: Optional[str] = None, ncols: int = 4, pointsize: Union[None, float] = None, figsize: tuple = (6, 4), show_legend='on data', use_smoothed: bool = True, aggregate: Optional[str] = None, show_arrowed_spines: bool = False, ax: Optional[matplotlib.axes.Axes] = None, sort: str = 'raw', save_show_or_return: typing_extensions.Literal[save, show, return, both, all] = 'show', save_kwargs: Optional[Dict] = None, return_all: bool = False, add_gamma_fit: bool = False, frontier: bool = False, contour: bool = False, ccmap: Optional[str] = None, alpha: float = 0.1, calpha: float = 0.4, sym_c: bool = False, smooth: bool = False, dpi: int = 100, inset_dict: dict = {}, marker: str = None, group: str = None, add_group_gamma_fit: bool = False, affine_transform_degree: int = None, affine_transform_A: Optional[numpy.ndarray] = None, affine_transform_b: Optional[numpy.ndarray] = None, stack_colors: bool = False, stack_colors_threshold: float = 0.001, stack_colors_title: str = 'stacked colors', stack_colors_legend_size: int = 2, stack_colors_cmaps: Optional[str] = None, despline: bool = True, deaxis: bool = True, despline_sides: Union[None, List[str]] = None, projection: str = '2d', geo: bool = False, boundary_width: float = 0.2, boundary_color: str = 'black', aspect: str = 'auto', slices: Optional[int] = None, img_layers: Optional[int] = None, vf_plot_method: typing_extensions.Literal[cell, grid, stream] = 'cell', vf_kwargs: Optional[Dict[str, Union[str, int, float]]] = None, **kwargs) None | matplotlib.axes.Axes#

Plot an embedding as points. Currently, this only works for 2D embeddings. While there are many optional parameters to further control and tailor the plotting, you need only pass in the trained/fit umap model to get results. This plot utility will attempt to do the hard work of avoiding overplotting issues, and make it easy to automatically colour points by a categorical labelling or numeric values. This method is intended to be used within a Jupyter notebook with %matplotlib inline.

Parameters:
adata

AnnData an Anndata object

basis

str The reduced dimension.

vf_key

Optional, key in .obsm containing vector field information

X_grid

Optional, array containing grid points for vector field plots

V

Optional, array containing vector fields

x

int (default: 0) The column index of the low dimensional embedding for the x-axis.

y

int (default: 1) The column index of the low dimensional embedding for the y-axis.

color

string (default: ntr) Any column names or gene expression, etc. that will be used for coloring cells.

layer

str (default: X) The layer of data to use for the scatter plot.

highlights

list (default: None) Which color group will be highlighted. if highlights is a list of lists - each list is relate to each color element.

labels

array, shape (n_samples,) (optional, default None) An array of labels (assumed integer or categorical), one for each data sample. This will be used for coloring the points in the plot according to their label. Note that this option is mutually exclusive to the values option.

values

array, shape (n_samples,) (optional, default None) An array of values (assumed float or continuous), one for each sample. This will be used for coloring the points in the plot according to a colorscale associated to the total range of values. Note that this option is mutually exclusive to the labels option.

theme

string (optional, default None) A color theme to use for plotting. A small set of predefined themes are provided which have relatively good aesthetics. Available themes are:

  • ’blue’

  • ’red’

  • ’green’

  • ’inferno’

  • ’fire’

  • ’viridis’

  • ’darkblue’

  • ’darkred’

  • ’darkgreen’

cmap

string (optional, default ‘Blues’) The name of a matplotlib colormap to use for coloring or shading points. If no labels or values are passed this will be used for shading points according to density (largely only of relevance for very large datasets). If values are passed this will be used for shading according the value. Note that if theme is passed then this value will be overridden by the corresponding option of the theme.

color_key

dict or array, shape (n_categories) (optional, default None) A way to assign colors to categoricals. This can either be an explicit dict mapping labels to colors (as strings of form ‘#RRGGBB’), or an array like object providing one color for each distinct category being provided in labels. Either way this mapping will be used to color points according to the label. Note that if theme is passed then this value will be overridden by the corresponding option of the theme.

color_key_cmap

The name of a matplotlib colormap to use for categorical coloring. If an explicit color_key is not given a color mapping for categories can be generated from the label list and selecting a matching list of colors from the given colormap. Note that if theme is passed then this value will be overridden by the corresponding option of the theme.

background

string or None (optional, default ‘None`) The color of the background. Usually this will be either ‘white’ or ‘black’, but any color name will work. Ideally one wants to match this appropriately to the colors being used for points etc. This is one of the things that themes handle for you. Note that if theme is passed then this value will be overridden by the corresponding option of the theme.

ncols

int (optional, default 4) Number of columns for the figure.

pointsize

None or float (default: None) The scale of the point size. Actual point cell size is calculated as 500.0 / np.sqrt(adata.shape[0]) * pointsize

figsize

None or [float, float] (default: None) The width and height of a figure.

show_legend

bool (optional, default True) Whether to display a legend of the labels

use_smoothed

bool (optional, default True) Whether to use smoothed values (i.e. M_s / M_u instead of spliced / unspliced, etc.).

aggregate

str or None (default: None) The column in adata.obs that will be used to aggregate data points.

show_arrowed_spines

bool (optional, default False) Whether to show a pair of arrowed spines representing the basis of the scatter is currently using.

ax

matplotlib.Axis (optional, default None) The matplotlib axes object where new plots will be added to. Only applicable to drawing a single component.

sort

str (optional, default raw) The method to reorder data so that high values points will be on top of background points. Can be one of {‘raw’, ‘abs’, ‘neg’}, i.e. sorted by raw data, sort by absolute values or sort by negative values.

save_show_or_return

Whether to save, show or return the figure. If “both”, it will save and plot the figure at the same time. If “all”, the figure will be saved, displayed and the associated axis and other object will be return.

save_kwargs

A dictionary that will be passed to the save_fig function. By default, it is an empty dictionary and the save_fig function will use the {“path”: None, “prefix”: ‘scatter’, “dpi”: None, “ext”: ‘pdf’, “transparent”: True, “close”: True, “verbose”: True} as its parameters. Otherwise, you can provide a dictionary that properly modify those keys according to your needs.

return_all

bool (default: False) Whether to return all the scatter related variables. Default is False.

add_gamma_fit

bool (default: False) Whether to add the line of the gamma fitting. This will automatically turn on if basis points to gene names and those genes have went through gamma fitting.

frontier

bool (default: False) Whether to add the frontier. Scatter plots can be enhanced by using transparency (alpha) in order to show area of high density and multiple scatter plots can be used to delineate a frontier. See matplotlib tips & tricks cheatsheet (https://github.com/matplotlib/cheatsheets). Originally inspired by figures from scEU-seq paper: https://science.sciencemag.org/content/367/6482/1151. If contour is set to be True, frontier will be ignored as contour also add an outlier for data points.

contour

bool (default: False) Whether to add an countor on top of scatter plots. We use tricontourf to plot contour for non-gridded data. The shapely package was used to create a polygon of the concave hull of the scatters. With the polygon we then check if the mean of the triangulated points are within the polygon and use this as our condition to form the mask to create the contour. We also add the polygon shape as a frontier of the data point (similar to when setting frontier = True). When the color of the data points is continuous, we will use the same cmap as for the scatter points by default, when color is categorical, no contour will be drawn but just the polygon. cmap can be set with ccmap argument. See below. This has recently changed to use seaborn’s kdeplot.

ccmap

str or None (default: None) The name of a matplotlib colormap to use for coloring or shading points the contour. See above.

calpha

float (default: 0.4) Contour alpha value passed into sns.kdeplot. The value should be inbetween [0, 1]

sym_c

bool (default: False) Whether do you want to make the limits of continuous color to be symmetric, normally this should be used for plotting velocity, jacobian, curl, divergence or other types of data with both positive or negative values.

smooth

bool or int (default: False) Whether do you want to further smooth data and how much smoothing do you want. If it is False, no smoothing will be applied. If True, smoothing based on one step diffusion of connectivity matrix (.uns[‘moment_cnn’] will be applied. If a number larger than 1, smoothing will based on `smooth steps of diffusion.

dpi

float, (default: 100.0) The resolution of the figure in dots-per-inch. Dots per inches (dpi) determines how many pixels the figure comprises. dpi is different from ppi or points per inches. Note that most elements like lines, markers, texts have a size given in points so you can convert the points to inches. Matplotlib figures use Points per inch (ppi) of 72. A line with thickness 1 point will be 1./72. inch wide. A text with fontsize 12 points will be 12./72. inch heigh. Of course if you change the figure size in inches, points will not change, so a larger figure in inches still has the same size of the elements.Changing the figure size is thus like taking a piece of paper of a different size. Doing so, would of course not change the width of the line drawn with the same pen. On the other hand, changing the dpi scales those elements. At 72 dpi, a line of 1 point size is one pixel strong. At 144 dpi, this line is 2 pixels strong. A larger dpi will therefore act like a magnifying glass. All elements are scaled by the magnifying power of the lens. see more details at answer 2 by @ImportanceOfBeingErnest: https://stackoverflow.com/questions/47633546/relationship-between-dpi-and-figure-size

inset_dict

dict (default: {}) A dictionary of parameters in inset_ax. Example, something like {“width”: “5%”, “height”: “50%”, “loc”: ‘lower left’, “bbox_to_anchor”: (0.85, 0.90, 0.145, 0.145), “bbox_transform”: ax.transAxes, “borderpad”: 0} See more details at https://matplotlib.org/api/_as_gen/mpl_toolkits.axes_grid1.inset_locator.inset_axes.html or https://stackoverflow.com/questions/39803385/what-does-a-4-element-tuple-argument-for-bbox-to-anchor-mean -in-matplotlib

marker

str (default: None) The marker style. marker can be either an instance of the class or the text shorthand for a particular marker. See matplotlib.markers for more information about marker styles.

group

The key to the column in adata.obs that points to cell groups that will be used to include the gamma fittings.

add_group_gamma_fit

Whether or not to add the gamma fitting line for each cell group.

affine_transform_degree

Transform coordinates of points according to some degree.

affine_transform_A

Coefficients in affine transformation Ax + b. 2D for now.

affine_transform_b

Bias in affine transformation Ax + b.

stack_colors

Whether to stack all color on the same ax passed above. Currently only support 18 sequential matplotlib default cmaps assigning to different color groups. (#colors should be smaller than 18, reuse if #colors > 18. To-do: generate cmaps according to #colors)

stack_colors_threshold

A threshold for filtering points values < threshold when drawing each color. E.g. if you do not want points with values < 1 showing up on axis, set threshold to be 1

stack_colors_title

The title for the stack_color plot.

stack_colors_legend_size

Control the legend size in stack color plot.

stack_colors_cmaps

The colormap used to stack different genes in a single plot.

despline

Whether to remove splines of the figure.

despline_sides

Which side of splines should be removed. Can be any combination of [“bottom”, “right”, “top”, “left”].

deaxis

Whether to remove axis ticks of the figure.

projection

The projection of the figure. Can be “2d”, “3d”, “polar”, etc.

geo

bool (default: False) Use geometry info or not.

boundary_width

float, (default: 0.2) The line width of boundary.

boundary_color

(default: “black”) The color value of boundary.

aspect

Set the aspect of the axis scaling, i.e. the ratio of y-unit to x-unit. In physical spatial plot, the default is ‘equal’. See more details at: https://matplotlib.org/stable/api/_as_gen/matplotlib.axes.Axes.set_aspect.html

slices

The index to the tissue slice, will used in adata.uns[“spatial”][slices].

img_layers

The index to the (staining) image of a tissue slice, will be used in adata.uns[“spatial”][slices][“images”].

vf_plot_method

The method used to plot the vector field. Can be one of the following: ‘cell’: Plot the vector field at the center of each cell. ‘grid’: Plot the vector field on a grid. ‘stream’: Plot the vector field as stream lines.

vf_kwargs

Optional dictionary containing parameters for vector field plotting

kwargs

Additional arguments passed to plt functions (plt.scatters, plt.quiver, plt.streamplot).

Returns:

Either None or a matplotlib axis with the relevant plot displayed. If you are using a notbooks and have %matplotlib inline set then this will simply display inline.

Return type:

result

spateo.plotting.static.space(adata: anndata.AnnData, color: List[str] | str | None | None = None, genes: List[str] = [], gene_cmaps=None, space: str = 'spatial', width: float = 6, marker: str = '.', pointsize: float | None = None, dpi: int = 100, ps_sample_num: int = 1000, alpha: float = 0.8, stack_genes: bool = False, stack_genes_threshold: float = 0.01, stack_colors_legend_size: int = 10, figsize=None, *args, **kwargs)[source]#

Scatter plot for physical coordinates of each cell.

Parameters:
adata

An AnnData object that contains the physical coordinates for each bin/cell, etc.

genes

The gene list that will be used to plot the gene expression on the same scatter plot. Each gene will have a different color.

color

string (default: ntr) Any or any list of column names or gene name, etc. that will be used for coloring cells. If color is not None, stack_genes will be disabled automatically because color can contain non numerical values.

space

The key to space coordinates.

stack_genes

Whether to show all gene plots on the same plot

stack_genes_threshold

Lower bound of gene values that will be drawn on the plot

stack_colors_legend_size

Control the size of legend when stacking genes

alpha

The alpha value of the scatter points

width

Width of the figure

marker

A string representing some marker from matplotlib https://matplotlib.org/stable/api/markers_api.html#module-matplotlib.markers

pointsize

The size of the points on the scatter plot

dpi

float, (default: 100.0) The resolution of the figure in dots-per-inch. Dots per inches (dpi) determines how many pixels the figure comprises. dpi is different from ppi or points per inches. Note that most elements like lines, markers, texts have a size given in points so you can convert the points to inches. Matplotlib figures use Points per inch (ppi) of 72. A line with thickness 1 point will be 1./72. inch wide. A text with fontsize 12 points will be 12./72. inch heigh. Of course if you change the figure size in inches, points will not change, so a larger figure in inches still has the same size of the elements.Changing the figure size is thus like taking a piece of paper of a different size. Doing so, would of course not change the width of the line drawn with the same pen. On the other hand, changing the dpi scales those elements. At 72 dpi, a line of 1 point size is one pixel strong. At 144 dpi, this line is 2 pixels strong. A larger dpi will therefore act like a magnifying glass. All elements are scaled by the magnifying power of the lens. see more details at answer 2 by @ImportanceOfBeingErnest: https://stackoverflow.com/questions/47633546/relationship-between-dpi-and-figure-size

ps_sample_num

The number of bins / cells that will be sampled to estimate the distance between different bin / cells

% scatters.parameters.no_adata|basis|figsize

Returns:

plots gene or cell feature of the adata object on the physical spatial coordinates.

spateo.plotting.static.acceleration(adata: anndata.AnnData, model: pyvista.PolyData | pyvista.UnstructuredGrid | pyvista.MultiBlock | list, acceleration_key: str = 'acceleration', filename: str | None = None, jupyter: bool | Literal[none, static, trame] = False, colormap: str | list | None = 'default_cmap', ambient: float | list = 0.2, opacity: float | numpy.ndarray | list = 1.0, model_style: Literal[points, surface, wireframe] | list = 'points', model_size: float | list = 3.0, **kwargs)[source]#

Visualize the torsion result.

Parameters:
adata

An anndata object contain acceleration values in .obs[acceleration_key].

model

A reconstructed model contains obs_index values.

acceleration_key

The key in .obs that corresponds to the acceleration values in the anndata object.

filename

Filename of output file. Writer type is inferred from the extension of the filename.

  • Output an image file,please enter a filename ending with '.png', '.tif', '.tiff', '.bmp', '.jpeg', '.jpg', '.svg', '.eps', '.ps', '.pdf', '.tex'. When jupyter=False, if you want to save ‘.png’ file, please ensure off_screen=True.

  • Output a gif file, please enter a filename ending with .gif.

  • Output a mp4 file, please enter a filename ending with .mp4.

jupyter

Whether to plot in jupyter notebook. Available jupyter are:

  • 'none' - Do not display in the notebook.

  • 'trame' - Show a trame widget

  • 'static' - Display a static figure.

colormap

Name of the Matplotlib colormap to use when mapping the scalars.

When the colormap is None, use {key}_rgba to map the scalars, otherwise use the colormap to map scalars.

ambient

When lighting is enabled, this is the amount of light in the range of 0 to 1 (default 0.0) that reaches the actor when not directed at the light source emitted from the viewer.

opacity

Opacity of the model.

If a single float value is given, it will be the global opacity of the model and uniformly applied everywhere, elif a numpy.ndarray with single float values is given, it will be the opacity of each point. - should be between 0 and 1.

A string can also be specified to map the scalars range to a predefined opacity transfer function (options include: ‘linear’, ‘linear_r’, ‘geom’, ‘geom_r’).

model_style

Visualization style of the model. One of the following:

  • model_style = 'surface',

  • model_style = 'wireframe',

  • model_style = 'points'.

model_size

If model_style = 'points', point size of any nodes in the dataset plotted.

If model_style = 'wireframe', thickness of lines.

**kwargs

Additional parameters that will be passed into the st.pl.feature function.

Returns:

List of camera position, focal point, and view up.

Returned only if filename is None or filename ending with '.png', '.tif', '.tiff', '.bmp', '.jpeg', '.jpg', '.svg', '.eps', '.ps', '.pdf', '.tex'.

img: Numpy array of the last image.

Returned only if filename is None or filename ending with '.png', '.tif', '.tiff', '.bmp', '.jpeg', '.jpg', '.svg', '.eps', '.ps', '.pdf', '.tex'.

Return type:

cpo

Examples

Visualize only in one model:

st.pl.acceleration(

adata=stage_adata, model=stage_pc, acceleration_key=”acceleration”, jupyter=”static”, model_style=”points”, model_size=3

)

Visualize in multiple model:

st.pl.acceleration(

adata=stage_adata, model=[stage_pc, trajectory_model], acceleration_key=”acceleration”, jupyter=”static”, model_style=[“points”, “wireframe”], model_size=[3, 1]

)

spateo.plotting.static.backbone(backbone_model: pyvista.PolyData, backbone_key: str = 'backbone', backbone_model_size: float | int = 8, backbone_colormap: str | None = None, backbone_ambient: float | list = 0.2, backbone_opacity: float | numpy.ndarray | list = 1.0, nodes_key: str | None = 'nodes', nodes_label_size: float | int = 18, bg_model: pyvista.PolyData | pyvista.UnstructuredGrid | pyvista.MultiBlock | None = None, bg_key: str | list | None = None, bg_model_style: Literal[points, surface, wireframe] | list = 'points', bg_model_size: float | list = 10, bg_colormap: str | list | None = None, bg_ambient: float | list = 0.2, bg_opacity: float | numpy.ndarray | list = 0.6, show_axes: bool = True, show_legend: bool = True, legend_kwargs: dict | None = None, filename: str | None = None, jupyter: bool | Literal[none, static, trame] = False, off_screen: bool = False, window_size: tuple = (2048, 2048), background: str = 'white', cpo: str | list = 'iso', **kwargs)[source]#

Visualize constructed 3D backbone model.

Parameters:
backbone_model

The constructed backbone model.

backbone_key

Any point_data names or cell_data names to be used for coloring backbone_model.

backbone_model_size

The thickness of backbone.

backbone_colormap

Name of the Matplotlib colormap to use when mapping the scalars of backbone_model.

When the colormap is None, use {key}_rgba to map the scalars, otherwise use the colormap to map scalars.

backbone_ambient

When lighting is enabled, this is the amount of light in the range of 0 to 1 (default 0.0) that reaches the actor when not directed at the light source emitted from the viewer.

backbone_opacity

Opacity of the model.

If a single float value is given, it will be the global opacity of the model and uniformly applied everywhere, elif a numpy.ndarray with single float values is given, it will be the opacity of each point. - should be between 0 and 1.

A string can also be specified to map the scalars range to a predefined opacity transfer function (options include: ‘linear’, ‘linear_r’, ‘geom’, ‘geom_r’).

nodes_key

The key that corresponds to the coordinates of the nodes in the backbone.

nodes_label_size

Sets the size of the title font.

bg_model

The background model used to construct backbone model.

bg_key

Any point_data names or cell_data names to be used for coloring bg_model.

bg_model_style

Visualization style of bg_model. One of the following:

  • bg_model_style = 'surface',

  • bg_model_style = 'wireframe',

  • bg_model_style = 'points'.

bg_model_size

If bg_model_style = 'points', point size of any nodes in the dataset plotted.

If bg_model_style = 'wireframe', thickness of lines.

bg_colormap

Name of the Matplotlib colormap to use when mapping the scalars of bg_model.

When the colormap is None, use {key}_rgba to map the scalars, otherwise use the colormap to map scalars.

bg_ambient

When lighting is enabled, this is the amount of light in the range of 0 to 1 (default 0.0) that reaches the actor when not directed at the light source emitted from the viewer.

bg_opacity

Opacity of the model.

If a single float value is given, it will be the global opacity of the model and uniformly applied everywhere, elif a numpy.ndarray with single float values is given, it will be the opacity of each point. - should be between 0 and 1.

A string can also be specified to map the scalars range to a predefined opacity transfer function (options include: ‘linear’, ‘linear_r’, ‘geom’, ‘geom_r’).

show_axes

Whether to add a camera orientation widget to the active renderer.

show_legend

whether to add a legend of bg_model to the plotter.

legend_kwargs

A dictionary that will be pass to the add_legend function. By default, it is an empty dictionary and the add_legend function will use the {"legend_size": None, "legend_loc": None,  "legend_size": None, "legend_loc": None, "title_font_size": None, "label_font_size": None, "font_family": "arial", "fmt": "%.2e", "n_labels": 5, "vertical": True} as its parameters. Otherwise, you can provide a dictionary that properly modify those keys according to your needs.

filename

Filename of output file. Writer type is inferred from the extension of the filename.

  • Output an image file,please enter a filename ending with '.png', '.tif', '.tiff', '.bmp', '.jpeg', '.jpg', '.svg', '.eps', '.ps', '.pdf', '.tex'. When jupyter=False, if you want to save ‘.png’ file, please ensure off_screen=True.

jupyter

Whether to plot in jupyter notebook. Available jupyter are:

  • 'none' - Do not display in the notebook.

  • 'trame' - Show a trame widget

  • 'static' - Display a static figure.

off_screen

Renders off-screen when True. Useful for automated screenshots.

window_size

Window size in pixels. The default window_size is [512, 512].

background

The background color of the window.

cpo

Camera position of the active render window. Available cpo are:

  • Iterable containing position, focal_point, and view up.

    E.g.: [(2.0, 5.0, 13.0), (0.0, 0.0, 0.0), (-0.7, -0.5, 0.3)].

  • Iterable containing a view vector.

    E.g.: [-1.0, 2.0, -5.0].

  • A string containing the plane orthogonal to the view direction.

    E.g.: 'xy', 'xz', 'yz', 'yx', 'zx', 'zy', 'iso'.

**kwargs

Additional parameters that will be passed to .add_point_labels function.

Returns:

List of camera position, focal point, and view up.

Returned only if filename is None or filename ending with '.png', '.tif', '.tiff', '.bmp', '.jpeg', '.jpg', '.svg', '.eps', '.ps', '.pdf', '.tex'.

img: Numpy array of the last image.

Returned only if filename is None or filename ending with '.png', '.tif', '.tiff', '.bmp', '.jpeg', '.jpg', '.svg', '.eps', '.ps', '.pdf', '.tex'.

Return type:

cpo

spateo.plotting.static.curl(adata: anndata.AnnData, model: pyvista.PolyData | pyvista.UnstructuredGrid | pyvista.MultiBlock | list, curl_key: str = 'curl', filename: str | None = None, jupyter: bool | Literal[none, static, trame] = False, colormap: str | list | None = 'default_cmap', ambient: float | list = 0.2, opacity: float | numpy.ndarray | list = 1.0, model_style: Literal[points, surface, wireframe] | list = 'points', model_size: float | list = 3.0, **kwargs)[source]#

Visualize the curl result.

Parameters:
adata

An anndata object contain curl values in .obs[curl_key].

model

A reconstructed model contains obs_index values.

curl_key

The key in .obs that corresponds to the curl values in the anndata object.

filename

Filename of output file. Writer type is inferred from the extension of the filename.

  • Output an image file,please enter a filename ending with '.png', '.tif', '.tiff', '.bmp', '.jpeg', '.jpg', '.svg', '.eps', '.ps', '.pdf', '.tex'. When jupyter=False, if you want to save ‘.png’ file, please ensure off_screen=True.

  • Output a gif file, please enter a filename ending with .gif.

  • Output a mp4 file, please enter a filename ending with .mp4.

jupyter

Whether to plot in jupyter notebook. Available jupyter are:

  • 'none' - Do not display in the notebook.

  • 'trame' - Show a trame widget

  • 'static' - Display a static figure.

colormap

Name of the Matplotlib colormap to use when mapping the scalars.

When the colormap is None, use {key}_rgba to map the scalars, otherwise use the colormap to map scalars.

ambient

When lighting is enabled, this is the amount of light in the range of 0 to 1 (default 0.0) that reaches the actor when not directed at the light source emitted from the viewer.

opacity

Opacity of the model.

If a single float value is given, it will be the global opacity of the model and uniformly applied everywhere, elif a numpy.ndarray with single float values is given, it will be the opacity of each point. - should be between 0 and 1.

A string can also be specified to map the scalars range to a predefined opacity transfer function (options include: ‘linear’, ‘linear_r’, ‘geom’, ‘geom_r’).

model_style

Visualization style of the model. One of the following:

  • model_style = 'surface',

  • model_style = 'wireframe',

  • model_style = 'points'.

model_size

If model_style = 'points', point size of any nodes in the dataset plotted.

If model_style = 'wireframe', thickness of lines.

**kwargs

Additional parameters that will be passed into the st.pl.feature function.

Returns:

List of camera position, focal point, and view up.

Returned only if filename is None or filename ending with '.png', '.tif', '.tiff', '.bmp', '.jpeg', '.jpg', '.svg', '.eps', '.ps', '.pdf', '.tex'.

img: Numpy array of the last image.

Returned only if filename is None or filename ending with '.png', '.tif', '.tiff', '.bmp', '.jpeg', '.jpg', '.svg', '.eps', '.ps', '.pdf', '.tex'.

Return type:

cpo

Examples

Visualize only in one model:

st.pl.curl(

adata=stage_adata, model=stage_pc, curl_key=”curl”, jupyter=”static”, model_style=”points”, model_size=3

)

Visualize in multiple model:

st.pl.curl(

adata=stage_adata, model=[stage_pc, trajectory_model], curl_key=”curl”, jupyter=”static”, model_style=[“points”, “wireframe”], model_size=[3, 1]

)

spateo.plotting.static.curvature(adata: anndata.AnnData, model: pyvista.PolyData | pyvista.UnstructuredGrid | pyvista.MultiBlock | list, curvature_key: str = 'curvature', filename: str | None = None, jupyter: bool | Literal[none, static, trame] = False, colormap: str | list | None = 'default_cmap', ambient: float | list = 0.2, opacity: float | numpy.ndarray | list = 1.0, model_style: Literal[points, surface, wireframe] | list = 'points', model_size: float | list = 3.0, **kwargs)[source]#

Visualize the curvature result.

Parameters:
adata

An anndata object contain curvature values in .obs[curvature_key].

model

A reconstructed model contains obs_index values.

curvature_key

The key in .obs that corresponds to the curvature values in the anndata object.

filename

Filename of output file. Writer type is inferred from the extension of the filename.

  • Output an image file,please enter a filename ending with '.png', '.tif', '.tiff', '.bmp', '.jpeg', '.jpg', '.svg', '.eps', '.ps', '.pdf', '.tex'. When jupyter=False, if you want to save ‘.png’ file, please ensure off_screen=True.

  • Output a gif file, please enter a filename ending with .gif.

  • Output a mp4 file, please enter a filename ending with .mp4.

jupyter

Whether to plot in jupyter notebook. Available jupyter are:

  • 'none' - Do not display in the notebook.

  • 'trame' - Show a trame widget

  • 'static' - Display a static figure.

colormap

Name of the Matplotlib colormap to use when mapping the scalars.

When the colormap is None, use {key}_rgba to map the scalars, otherwise use the colormap to map scalars.

ambient

When lighting is enabled, this is the amount of light in the range of 0 to 1 (default 0.0) that reaches the actor when not directed at the light source emitted from the viewer.

opacity

Opacity of the model.

If a single float value is given, it will be the global opacity of the model and uniformly applied everywhere, elif a numpy.ndarray with single float values is given, it will be the opacity of each point. - should be between 0 and 1.

A string can also be specified to map the scalars range to a predefined opacity transfer function (options include: ‘linear’, ‘linear_r’, ‘geom’, ‘geom_r’).

model_style

Visualization style of the model. One of the following:

  • model_style = 'surface',

  • model_style = 'wireframe',

  • model_style = 'points'.

model_size

If model_style = 'points', point size of any nodes in the dataset plotted.

If model_style = 'wireframe', thickness of lines.

**kwargs

Additional parameters that will be passed into the st.pl.feature function.

Returns:

List of camera position, focal point, and view up.

Returned only if filename is None or filename ending with '.png', '.tif', '.tiff', '.bmp', '.jpeg', '.jpg', '.svg', '.eps', '.ps', '.pdf', '.tex'.

img: Numpy array of the last image.

Returned only if filename is None or filename ending with '.png', '.tif', '.tiff', '.bmp', '.jpeg', '.jpg', '.svg', '.eps', '.ps', '.pdf', '.tex'.

Return type:

cpo

Examples

Visualize only in one model:

st.pl.curvature(

adata=stage_adata, model=stage_pc, curvature_key=”curvature”, jupyter=”static”, model_style=”points”, model_size=3

)

Visualize in multiple model:

st.pl.curvature(

adata=stage_adata, model=[stage_pc, trajectory_model], curvature_key=”curvature”, jupyter=”static”, model_style=[“points”, “wireframe”], model_size=[3, 1]

)

spateo.plotting.static.deformation(*adata: anndata.AnnData, deformed_grid: pyvista.PolyData | List[pyvista.PolyData], layer: str = 'X', group_key: str | list = None, spatial_key: str = 'align_spatial', id_key: str = 'slices', deformation_key: str | None = 'deformation', center_zero: bool = False, show_model: bool = True, filename: str | None = None, jupyter: bool | Literal[none, static, trame] = False, off_screen: bool = False, cpo: str | list = 'xy', shape: str | list | tuple = None, window_size: tuple | None = (1024, 756), background: str = 'white', model_color: str | list = 'red', model_alpha: float | list | dict = 1, colormap: str | list | dict = 'black', alphamap: float | list | dict = 1.0, ambient: float | list = 0.2, opacity: float | numpy.ndarray | list = 1.0, grid_size: float | list = 2.0, model_size: float | list = 3.0, show_axes: bool = True, show_legend: bool = False, legend_kwargs: dict | None = None, text: bool | str = True, text_kwargs: dict | None = None, **kwargs)[source]#
spateo.plotting.static.divergence(adata: anndata.AnnData, model: pyvista.PolyData | pyvista.UnstructuredGrid | pyvista.MultiBlock | list, divergence_key: str = 'divergence', filename: str | None = None, jupyter: bool | Literal[none, static, trame] = False, colormap: str | list | None = 'default_cmap', ambient: float | list = 0.2, opacity: float | numpy.ndarray | list = 1.0, model_style: Literal[points, surface, wireframe] | list = 'points', model_size: float | list = 3.0, **kwargs)[source]#

Visualize the divergence result.

Parameters:
adata

An anndata object contain curl values in .obs[divergence_key].

model

A reconstructed model contains obs_index values.

divergence_key

The key in .obs that corresponds to the divergence values in the anndata object.

filename

Filename of output file. Writer type is inferred from the extension of the filename.

  • Output an image file,please enter a filename ending with '.png', '.tif', '.tiff', '.bmp', '.jpeg', '.jpg', '.svg', '.eps', '.ps', '.pdf', '.tex'. When jupyter=False, if you want to save ‘.png’ file, please ensure off_screen=True.

  • Output a gif file, please enter a filename ending with .gif.

  • Output a mp4 file, please enter a filename ending with .mp4.

jupyter

Whether to plot in jupyter notebook. Available jupyter are:

  • 'none' - Do not display in the notebook.

  • 'pythreejs' - Show a pythreejs widget

  • 'static' - Display a static figure.

  • 'ipygany' - Show an ipygany widget

  • 'panel' - Show a panel widget.

colormap

Name of the Matplotlib colormap to use when mapping the scalars.

When the colormap is None, use {key}_rgba to map the scalars, otherwise use the colormap to map scalars.

ambient

When lighting is enabled, this is the amount of light in the range of 0 to 1 (default 0.0) that reaches the actor when not directed at the light source emitted from the viewer.

opacity

Opacity of the model.

If a single float value is given, it will be the global opacity of the model and uniformly applied everywhere, elif a numpy.ndarray with single float values is given, it will be the opacity of each point. - should be between 0 and 1.

A string can also be specified to map the scalars range to a predefined opacity transfer function (options include: ‘linear’, ‘linear_r’, ‘geom’, ‘geom_r’).

model_style

Visualization style of the model. One of the following:

  • model_style = 'surface',

  • model_style = 'wireframe',

  • model_style = 'points'.

model_size

If model_style = 'points', point size of any nodes in the dataset plotted.

If model_style = 'wireframe', thickness of lines.

**kwargs

Additional parameters that will be passed into the st.pl.feature function.

Returns:

List of camera position, focal point, and view up.

Returned only if filename is None or filename ending with '.png', '.tif', '.tiff', '.bmp', '.jpeg', '.jpg', '.svg', '.eps', '.ps', '.pdf', '.tex'.

img: Numpy array of the last image.

Returned only if filename is None or filename ending with '.png', '.tif', '.tiff', '.bmp', '.jpeg', '.jpg', '.svg', '.eps', '.ps', '.pdf', '.tex'.

Return type:

cpo

Examples

Visualize only in one model:

st.pl.divergence(

adata=stage_adata, model=stage_pc, divergence_key=”divergence”, jupyter=”static”, model_style=”points”, model_size=3

)

Visualize in multiple model:

st.pl.divergence(

adata=stage_adata, model=[stage_pc, trajectory_model], divergence_key=”divergence”, jupyter=”static”, model_style=[“points”, “wireframe”], model_size=[3, 1]

)

spateo.plotting.static.jacobian(adata: anndata.AnnData, model: pyvista.PolyData | pyvista.UnstructuredGrid | pyvista.MultiBlock | list, jacobian_key: str = 'jacobian', filename: str | None = None, jupyter: bool | Literal[none, static, trame] = False, off_screen: bool = False, shape: str | list | tuple = (3, 3), window_size: tuple | None = (512 * 3, 512 * 3), background: str = 'black', colormap: str | list | None = 'default_cmap', ambient: float | list = 0.2, opacity: float | numpy.ndarray | list = 1.0, model_style: Literal[points, surface, wireframe] | list = 'points', model_size: float | list = 3.0, show_axes: bool = True, show_legend: bool = True, legend_kwargs: dict | None = None, text: bool | str = True, text_kwargs: dict | None = None, **kwargs)[source]#

Visualize the jacobian result.

Parameters:
adata

An anndata object contain jacobian matrix in .uns[jacobian_key].

model

A reconstructed model contains obs_index values.

jacobian_key

The key in .uns that corresponds to the jacobian matrix in the anndata object.

filename

Filename of output file. Writer type is inferred from the extension of the filename.

  • Output an image file,please enter a filename ending with '.png', '.tif', '.tiff', '.bmp', '.jpeg', '.jpg', '.svg', '.eps', '.ps', '.pdf', '.tex'. When jupyter=False, if you want to save ‘.png’ file, please ensure off_screen=True.

  • Output a gif file, please enter a filename ending with .gif.

  • Output a mp4 file, please enter a filename ending with .mp4.

jupyter

Whether to plot in jupyter notebook. Available jupyter are:

  • 'none' - Do not display in the notebook.

  • 'trame' - Show a trame widget

  • 'static' - Display a static figure.

off_screen

Renders off-screen when True. Useful for automated screenshots.

shape

Number of sub-render windows inside the main window. By default, there are nine render window.

  • Specify two across with ``shape``=(2, 1) and a two by two grid with ``shape``=(2, 2).

  • shape Can also accept a string descriptor as shape.

    E.g.: shape="3|1" means 3 plots on the left and 1 on the right, E.g.: shape="4/2" means 4 plots on top and 2 at the bottom.

window_size

Window size in pixels. The default window_size is [512*3, 512*3].

background

The background color of the window.

colormap

Name of the Matplotlib colormap to use when mapping the scalars.

When the colormap is None, use {key}_rgba to map the scalars, otherwise use the colormap to map scalars.

ambient

When lighting is enabled, this is the amount of light in the range of 0 to 1 (default 0.0) that reaches the actor when not directed at the light source emitted from the viewer.

opacity

Opacity of the model.

If a single float value is given, it will be the global opacity of the model and uniformly applied everywhere, elif a numpy.ndarray with single float values is given, it will be the opacity of each point. - should be between 0 and 1.

A string can also be specified to map the scalars range to a predefined opacity transfer function (options include: ‘linear’, ‘linear_r’, ‘geom’, ‘geom_r’).

model_style

Visualization style of the model. One of the following:

  • model_style = 'surface',

  • model_style = 'wireframe',

  • model_style = 'points'.

model_size

If model_style = 'points', point size of any nodes in the dataset plotted.

If model_style = 'wireframe', thickness of lines.

show_axes

Whether to add a camera orientation widget to the active renderer.

show_legend

whether to add a legend to the plotter.

legend_kwargs

A dictionary that will be pass to the add_legend function. By default, it is an empty dictionary and the add_legend function will use the {"legend_size": None, "legend_loc": None,  "legend_size": None, "legend_loc": None, "title_font_size": None, "label_font_size": None, "font_family": "arial", "fmt": "%.2e", "n_labels": 5, "vertical": True} as its parameters. Otherwise, you can provide a dictionary that properly modify those keys according to your needs.

text

The text to add the rendering.

text_kwargs

A dictionary that will be pass to the add_text function.

By default, it is an empty dictionary and the add_legend function will use the { "font_family": "arial", "font_size": 12, "font_color": "black", "text_loc": "upper_left"} as its parameters. Otherwise, you can provide a dictionary that properly modify those keys according to your needs.

**kwargs

Additional parameters that will be passed into the st.pl.three_d_multi_plot function.

Returns:

List of camera position, focal point, and view up.

Returned only if filename is None or filename ending with '.png', '.tif', '.tiff', '.bmp', '.jpeg', '.jpg', '.svg', '.eps', '.ps', '.pdf', '.tex'.

img: Numpy array of the last image.

Returned only if filename is None or filename ending with '.png', '.tif', '.tiff', '.bmp', '.jpeg', '.jpg', '.svg', '.eps', '.ps', '.pdf', '.tex'.

Return type:

cpo

Examples

Visualize only in one model:

st.pl.jacobian(

adata=stage_adata, model=stage_pc, jacobian_key=”jacobian”, jupyter=”static”, model_style=”points”, model_size=3

)

Visualize in multiple model:

st.pl.jacobian(

adata=stage_adata, model=[stage_pc, trajectory_model], jacobian_key=”jacobian”, jupyter=”static”, model_style=[“points”, “wireframe”], model_size=[3, 1]

)

spateo.plotting.static.merge_animations(mp4_files: list | None = None, mp4_folder: list | None = None, filename: str = 'merged_animation.mp4')[source]#

Use MoviePy to compose a new animation and play multiple animations together in the new animation.

Parameters:
mp4_files

A list containing absolute paths to mp4 files that need to be played together.

mp4_folder

Absolute path to the folder containing all mp4 files that need to be played together. If mp4_files is provided, mp4_folder cannot also be provided.

filename

Absolute path to save the newly composed animation.

Examples

st.pl.merge_animations(mp4_files=[“animation1.mp4”, “animation2.mp4”], filename=f”merged_animation.mp4”)

spateo.plotting.static.multi_models(*adata: anndata.AnnData, layer: str = 'X', group_key: str | list = None, spatial_key: str = 'align_spatial', id_key: str = 'slices', mode: Literal[single, overlap, both] = 'single', center_zero: bool = False, filename: str | None = None, jupyter: bool | Literal[none, static, trame] = False, off_screen: bool = False, cpo: str | list = 'xy', shape: str | list | tuple = None, window_size: tuple | None = None, background: str = 'white', colormap: str | list | dict = 'red', overlap_cmap: str | list | dict = 'dodgerblue', alphamap: float | list | dict = 1.0, overlap_amap: float | list | dict = 0.5, ambient: float | list = 0.2, opacity: float | numpy.ndarray | list = 1.0, model_size: float | list = 3.0, show_axes: bool = True, show_legend: bool = True, legend_kwargs: dict | None = None, text: bool | str = True, text_kwargs: dict | None = None, **kwargs)[source]#

Visualize multiple models separately in one figure.

Parameters:
*adata

A list of models[Anndata object].

layer

If 'X', uses .X, otherwise uses the representation given by .layers[layer].

group_key

The key that stores clustering or annotation information in .obs, a gene name or a list of gene names in .var.

spatial_key

The key in .obsm that corresponds to the spatial coordinate of each bucket.

id_key

The key in .obs that corresponds to the model id of each bucket.

mode

Three modes of visualization. Available mode are:

  • 'single' - Visualize each model individually.

  • 'overlap' - Simultaneously visualize two models aligned front to back in one subplot.

  • 'both' - Simultaneously visualize both types above.

center_zero

Whether to move the center point of the model to the (0, 0, 0).

filename

Filename of output file. Writer type is inferred from the extension of the filename.

  • Output an image file,please enter a filename ending with '.png', '.tif', '.tiff', '.bmp', '.jpeg', '.jpg', '.svg', '.eps', '.ps', '.pdf', '.tex'. When jupyter=False, if you want to save ‘.png’ file, please ensure off_screen=True.

jupyter

Whether to plot in jupyter notebook. Available jupyter are:

  • 'none' - Do not display in the notebook.

  • 'trame' - Show a trame widget

  • 'static' - Display a static figure.

off_screen

Renders off-screen when True. Useful for automated screenshots.

cpo

Camera position of the active render window. Available cpo are:

  • Iterable containing position, focal_point, and view up.

    E.g.: [(2.0, 5.0, 13.0), (0.0, 0.0, 0.0), (-0.7, -0.5, 0.3)].

  • Iterable containing a view vector.

    E.g.: [-1.0, 2.0, -5.0].

  • A string containing the plane orthogonal to the view direction.

    E.g.: 'xy', 'xz', 'yz', 'yx', 'zx', 'zy', 'iso'.

shape

Number of sub-render windows inside the main window. By default, there is only one render window.

  • Specify two across with ``shape``=(2, 1) and a two by two grid with ``shape``=(2, 2).

  • shape Can also accept a string descriptor as shape.

    E.g.: shape="3|1" means 3 plots on the left and 1 on the right, E.g.: shape="4/2" means 4 plots on top and 2 at the bottom.

window_size

Window size in pixels. The default window_size is [512, 512].

background

The background color of the window.

colormap

Colors to use for plotting pc. The default colormap is 'dodgerblue'.

overlap_cmap

Colors to use for plotting overlapped pc. The default colormap is 'red'.

alphamap

The opacity of the colors to use for plotting pc. The default alphamap is 1.0.

overlap_amap

The opacity of the colors to use for plotting overlapped pc. The default alphamap is .5.

ambient

When lighting is enabled, this is the amount of light in the range of 0 to 1 (default 0.0) that reaches the actor when not directed at the light source emitted from the viewer.

opacity

Opacity of the model.

If a single float value is given, it will be the global opacity of the model and uniformly applied everywhere, elif a numpy.ndarray with single float values is given, it will be the opacity of each point. - should be between 0 and 1.

A string can also be specified to map the scalars range to a predefined opacity transfer function (options include: ‘linear’, ‘linear_r’, ‘geom’, ‘geom_r’).

model_size

The point size of any nodes in the dataset plotted.

show_axes

Whether to add a camera orientation widget to the active renderer.

show_legend

whether to add a legend to the plotter.

legend_kwargs

A dictionary that will be pass to the add_legend function.

By default, it is an empty dictionary and the add_legend function will use the {"legend_size": None, "legend_loc": None,  "legend_size": None, "legend_loc": None, "title_font_size": None, "label_font_size": None, "font_family": "arial", "fmt": "%.2e", "n_labels": 5, "vertical": True} as its parameters. Otherwise, you can provide a dictionary that properly modify those keys according to your needs.

text

The text to add the rendering.

text_kwargs

A dictionary that will be pass to the add_text function.

By default, it is an empty dictionary and the add_legend function will use the { "font_family": "arial", "font_size": 12, "font_color": "black", "text_loc": "upper_left"} as its parameters. Otherwise, you can provide a dictionary that properly modify those keys according to your needs.

**kwargs

Additional parameters that will be passed to three_d_multi_plot function.

spateo.plotting.static.pairwise_iteration(adataA: anndata.AnnData, adataB: anndata.AnnData, layer: str = 'X', group_key: str | list = None, spatial_key: str = 'align_spatial', iter_key: str = 'iter_spatial', id_key: str = 'slices', filename: str = 'animate.mp4', jupyter: bool | Literal[none, static, trame] = False, off_screen: bool = False, cpo: str | list | None = None, window_size: tuple | None = None, background: str = 'black', modelA_cmap: str = 'dodgerblue', modelB_cmap: str = 'red', ambient: int | float = 0.3, modelA_opacity: int | float = 0.8, modelB_opacity: int | float = 1.0, model_size: float | list = 6.0, show_axes: bool = True, show_legend: bool = True, legend_kwargs: dict | None = None, text: bool | str = True, text_kwargs: dict | None = None, framerate: int = 6, **kwargs)[source]#

Visualize the results of each iteration in the alignment process.

Parameters:
adataA

Anndata object of modelA.

adataB

Anndata object of modelB.

layer

If 'X', uses .X, otherwise uses the representation given by .layers[layer].

group_key

The key that stores clustering or annotation information in .obs, a gene name or a list of gene names in .var.

spatial_key

The key in .obsm that corresponds to the spatial coordinate of each bucket.

iter_key

The key in .uns that corresponds to the result of each iteration of the iterative process.

id_key

The key in .obs that corresponds to the model id of each bucket.

filename

Filename of output file. Writer type is inferred from the extension of the filename.

  • Output a gif file, please enter a filename ending with .gif.

  • Output a mp4 file, please enter a filename ending with .mp4.

jupyter

Whether to plot in jupyter notebook. Available jupyter are:

  • 'none' - Do not display in the notebook.

  • 'trame' - Show a trame widget

  • 'static' - Display a static figure.

off_screen

Renders off-screen when True. Useful for automated screenshots.

cpo

Camera position of the active render window. Available cpo are:

  • Iterable containing position, focal_point, and view up.

    E.g.: [(2.0, 5.0, 13.0), (0.0, 0.0, 0.0), (-0.7, -0.5, 0.3)].

  • Iterable containing a view vector.

    E.g.: [-1.0, 2.0, -5.0].

  • A string containing the plane orthogonal to the view direction.

    E.g.: 'xy', 'xz', 'yz', 'yx', 'zx', 'zy', 'iso'.

window_size

Window size in pixels. The default window_size is [512, 512].

background

The background color of the window.

modelA_cmap

Colors to use for plotting modelA. The default colormap is 'dodgerblue'.

modelB_cmap

Colors to use for plotting modelB. The default colormap is 'red'.

ambient

When lighting is enabled, this is the amount of light in the range of 0 to 1 (default 0.0) that reaches the actor when not directed at the light source emitted from the viewer.

modelA_opacity

Opacity of the modelA.

modelB_opacity

Opacity of the modelB.

model_size

The point size of any nodes in the dataset plotted.

show_axes

Whether to add a camera orientation widget to the active renderer.

show_legend

whether to add a legend to the plotter.

legend_kwargs

A dictionary that will be pass to the add_legend function.

By default, it is an empty dictionary and the add_legend function will use the {"legend_size": None, "legend_loc": None,  "legend_size": None, "legend_loc": None, "title_font_size": None, "label_font_size": None, "font_family": "arial", "fmt": "%.2e", "n_labels": 5, "vertical": True} as its parameters. Otherwise, you can provide a dictionary that properly modify those keys according to your needs.

text

The text to add the rendering.

text_kwargs

A dictionary that will be pass to the add_text function.

By default, it is an empty dictionary and the add_legend function will use the { "font_family": "arial", "font_size": 12, "font_color": "black", "text_loc": "upper_left"} as its parameters. Otherwise, you can provide a dictionary that properly modify those keys according to your needs.

framerate

Frames per second.

**kwargs

Additional parameters that will be passed to three_d_animate function.

spateo.plotting.static.pairwise_mapping(idA: str = 'sampleA', idB: str = 'sampleB', adataA: anndata.AnnData | None = None, adataB: anndata.AnnData | None = None, pi: numpy.ndarray | None = None, modelA: pyvista.PolyData | None = None, modelB: pyvista.PolyData | None = None, model_lines: pyvista.PolyData | None = None, layer: str = 'X', group_key: str | list = None, spatial_key: str = 'align_spatial', keep_all: bool = False, distance: int | float | None = 300, direction: Literal[x, y, pairwise_mapping.z] | None = 'z', filename: str | None = None, jupyter: bool | Literal[none, static, trame] = False, off_screen: bool = False, cpo: str | list | None = 'iso', window_size: tuple | None = (1024, 1024), background: str = 'black', modelA_cmap: str = 'dodgerblue', modelA_amap: float | list = 1.0, modelB_cmap: str = 'red', modelB_amap: float | list = 1.0, line_color: str = 'gainsboro', line_alpha: float | list = 1.0, ambient: float = 0.3, model_opacity: float = 1, line_opacity: float = 0.03, model_size: float | list = 6.0, line_size: float | list = 2.0, show_axes: bool = True, show_legend: bool = True, legend_kwargs: dict | None = None, text: bool | str = True, text_kwargs: dict | None = None, **kwargs)[source]#

Visualize the pairing of cells between two models.

Parameters:
idA

ID of modelA.

idB

ID of modelB.

adataA

Anndata object of modelA.

adataB

Anndata object of modelB.

pi

The pi matrix obtained by alignment.

modelA

The point cloud model of adataA.

modelB

The point cloud model of adataB.

model_lines

Cell connection lines between modelA and modelB

layer

If 'X', uses .X, otherwise uses the representation given by .layers[layer].

group_key

The key that stores clustering or annotation information in .obs, a gene name or a list of gene names in .var.

spatial_key

The key in .obsm that corresponds to the spatial coordinate of each bucket.

keep_all

Whether to retain all the optimal relationships obtained only based on the pi matrix, If keep_all is False, the optimal relationships obtained based on the pi matrix and the nearest coordinates.

distance

Distance between modelA and modelB when visualizing.

direction

The direction between modelA and modelB when visualizing.

filename

Filename of output file. Writer type is inferred from the extension of the filename.

  • Output an image file,please enter a filename ending with '.png', '.tif', '.tiff', '.bmp', '.jpeg', '.jpg', '.svg', '.eps', '.ps', '.pdf', '.tex'. When jupyter=False, if you want to save ‘.png’ file, please ensure off_screen=True.

jupyter

Whether to plot in jupyter notebook. Available jupyter are:

  • 'none' - Do not display in the notebook.

  • 'trame' - Show a trame widget

  • 'static' - Display a static figure.

off_screen

Renders off-screen when True. Useful for automated screenshots.

cpo

Camera position of the active render window. Available cpo are:

  • Iterable containing position, focal_point, and view up.

    E.g.: [(2.0, 5.0, 13.0), (0.0, 0.0, 0.0), (-0.7, -0.5, 0.3)].

  • Iterable containing a view vector.

    E.g.: [-1.0, 2.0, -5.0].

  • A string containing the plane orthogonal to the view direction.

    E.g.: 'xy', 'xz', 'yz', 'yx', 'zx', 'zy', 'iso'.

window_size

Window size in pixels. The default window_size is (1024, 1024).

background

The background color of the window.

modelA_cmap

Colors to use for plotting modelA. The default colormap is 'dodgerblue'.

modelA_amap

The opacity of the colors to use for plotting modelA. The default alphamap is 1.0.

modelB_cmap

Colors to use for plotting modelB. The default colormap is 'red'.

modelB_amap

The opacity of the colors to use for plotting modelB. The default alphamap is 1.0.

line_color

Colors to use for plotting lines. The default colormap is 'gainsboro'.

line_alpha

Alpha to use for plotting lines. The default colormap is 'gainsboro'.

ambient

When lighting is enabled, this is the amount of light in the range of 0 to 1 (default 0.0) that reaches the actor when not directed at the light source emitted from the viewer.

model_opacity

Opacity of the modelA and modelB.

line_opacity

Opacity of the lines.

model_size

The point size of any nodes in the dataset plotted.

line_size

The line size of lines in the dataset plotted.

show_axes

Whether to add a camera orientation widget to the active renderer.

show_legend

whether to add a legend to the plotter.

legend_kwargs

A dictionary that will be pass to the add_legend function.

By default, it is an empty dictionary and the add_legend function will use the {"legend_size": None, "legend_loc": None,  "legend_size": None, "legend_loc": None, "title_font_size": None, "label_font_size": None, "font_family": "arial", "fmt": "%.2e", "n_labels": 5, "vertical": True} as its parameters. Otherwise, you can provide a dictionary that properly modify those keys according to your needs.

text

The text to add the rendering.

text_kwargs

A dictionary that will be pass to the add_text function.

By default, it is an empty dictionary and the add_legend function will use the { "font_family": "arial", "font_size": 12, "font_color": "black", "text_loc": "upper_left"} as its parameters. Otherwise, you can provide a dictionary that properly modify those keys according to your needs.

**kwargs

Additional parameters that will be passed to three_d_plot function.

Returns:

The point cloud models of adataA. pcB: The point cloud models of adataB. model_lines: Cell mapping lines between modelA and modelB.

Return type:

pcA

spateo.plotting.static.pi_heatmap(pi: numpy.ndarray, model1_name: str = 'model1', model2_name: str = 'model2', colormap: str = 'hot_r', fig_height: int | float = 3, robust: bool = False, vmin: int | float | None = None, vmax: int | float | None = None, fontsize: int | float = 12, filename: str | None = None, **kwargs)[source]#

Visualize a heatmap of the pi matrix.

Parameters:
pi

The pi matrix obtained by alignment.

model1_name

The name/id of model1.

model2_name

The name/id of model2.

colormap

Colors to use for plotting heatmap. The default colormap is 'hot_r'.

fig_height

Figure height.

robust

If True and vmin or vmax are absent, the colormap range is computed with robust quantiles instead of the extreme values.

vmin

Values to anchor the colormap, otherwise they are inferred from the data and other keyword arguments.

vmax

Values to anchor the colormap, otherwise they are inferred from the data and other keyword arguments.

fontsize

The font size of x label and y label.

filename

Filename of output file.

**kwargs

Additional parameters that will be passed to sns.heatmap function.

spateo.plotting.static.three_d_animate(models: Union[List[PolyData or UnstructuredGrid], pyvista.MultiBlock], stable_model: pyvista.PolyData | pyvista.UnstructuredGrid | pyvista.MultiBlock | None = None, stable_kwargs: dict | None = None, key: str | None = None, filename: str = 'animate.mp4', jupyter: bool | Literal[panel, none, pythreejs, static, ipygany] = False, off_screen: bool = False, window_size: tuple = (512, 512), background: str = 'white', cpo: str | list = 'iso', colormap: str | list | None = None, ambient: float | list = 0.2, opacity: float | numpy.ndarray | list = 1.0, model_style: Literal[points, surface, wireframe] | list = 'surface', model_size: float | list = 3.0, show_legend: bool = True, legend_kwargs: dict | None = None, show_outline: bool = False, outline_kwargs: dict | None = None, text: str | None = None, text_kwargs: dict | None = None, framerate: int = 24, plotter_filename: str | None = None)[source]#

Animated visualization of 3D reconstruction model.

Parameters:
models

A List of reconstructed models or a MultiBlock.

stable_model

The model that do not change with time in animation.

stable_kwargs

Parameters for plotting stable model. Available stable_kwargs are:

  • 'key'

  • 'ambient'

  • 'opacity'

  • 'model_style'

  • 'model_size'

  • 'background'

  • 'show_legend'

  • 'legend_kwargs'

  • 'show_outline'

  • 'outline_kwargs'

  • 'text'

  • 'text_kwargs'

key

The key under which are the labels.

filename

Filename of output file. Writer type is inferred from the extension of the filename.

  • Output a gif file, please enter a filename ending with .gif.

  • Output a mp4 file, please enter a filename ending with .mp4.

jupyter

Whether to plot in jupyter notebook. Available jupyter are:

  • 'none' - Do not display in the notebook.

  • 'pythreejs' - Show a pythreejs widget

  • 'static' - Display a static figure.

  • 'ipygany' - Show an ipygany widget

  • 'panel' - Show a panel widget.

off_screen

Renders off-screen when True. Useful for automated screenshots.

window_size

Window size in pixels. The default window_size is [512, 512].

background

The background color of the window.

cpo

Camera position of the active render window. Available cpo are:

  • Iterable containing position, focal_point, and view up.

    E.g.: [(2.0, 5.0, 13.0), (0.0, 0.0, 0.0), (-0.7, -0.5, 0.3)].

  • Iterable containing a view vector.

    E.g.: [-1.0, 2.0, -5.0].

  • A string containing the plane orthogonal to the view direction.

    E.g.: 'xy', 'xz', 'yz', 'yx', 'zx', 'zy', 'iso'.

colormap

Name of the Matplotlib colormap to use when mapping the scalars.

When the colormap is None, use {key}_rgba to map the scalars, otherwise use the colormap to map scalars.

ambient

When lighting is enabled, this is the amount of light in the range of 0 to 1 (default 0.0) that reaches the actor when not directed at the light source emitted from the viewer.

opacity

Opacity of the model.

If a single float value is given, it will be the global opacity of the model and uniformly applied everywhere, elif a numpy.ndarray with single float values is given, it will be the opacity of each point. - should be between 0 and 1.

A string can also be specified to map the scalars range to a predefined opacity transfer function (options include: ‘linear’, ‘linear_r’, ‘geom’, ‘geom_r’).

model_style

Visualization style of the model. One of the following:

  • model_style = 'surface',

  • model_style = 'wireframe',

  • model_style = 'points'.

model_size

If model_style = 'points', point size of any nodes in the dataset plotted.

If model_style = 'wireframe', thickness of lines.

show_legend

whether to add a legend to the plotter.

legend_kwargs

A dictionary that will be pass to the add_legend function. By default, it is an empty dictionary and the add_legend function will use the {"legend_size": None, "legend_loc": None,  "legend_size": None, "legend_loc": None, "title_font_size": None, "label_font_size": None, "font_family": "arial", "fmt": "%.2e", "n_labels": 5, "vertical": True} as its parameters. Otherwise, you can provide a dictionary that properly modify those keys according to your needs.

show_outline

whether to produce an outline of the full extent for the model.

outline_kwargs

A dictionary that will be pass to the add_outline function.

By default, it is an empty dictionary and the add_legend function will use the {"outline_width": 5.0, "outline_color": "black", "show_labels": True, "font_size": 16, "font_color": "white", "font_family": "arial"} as its parameters. Otherwise, you can provide a dictionary that properly modify those keys according to your needs.

text

The text to add the rendering.

text_kwargs

A dictionary that will be pass to the add_text function.

By default, it is an empty dictionary and the add_legend function will use the { "font_family": "arial", "font_size": 12, "font_color": "black", "text_loc": "upper_left"} as its parameters. Otherwise, you can provide a dictionary that properly modify those keys according to your needs.

framerate

Frames per second. Only available when filename ending with .mp4 or .gif.

plotter_filename

The filename of the file where the plotter is saved.

Writer type is inferred from the extension of the filename.

  • Output a gltf file, please enter a filename ending with .gltf.

  • Output a html file, please enter a filename ending with .html.

  • Output an obj file, please enter a filename ending with .obj.

  • Output a vtkjs file, please enter a filename without format.

spateo.plotting.static.three_d_multi_plot(model: pyvista.PolyData | pyvista.UnstructuredGrid | pyvista.MultiBlock, key: str | list = None, filename: str | None = None, jupyter: bool | Literal[panel, none, pythreejs, static, ipygany] = False, off_screen: bool = False, shape: str | list | tuple = None, window_size: tuple | None = None, background: str = 'white', cpo: str | list = 'iso', colormap: str | list | None = None, ambient: float | list = 0.2, opacity: float | numpy.ndarray | list = 1.0, model_style: Literal[points, surface, wireframe] | list = 'surface', model_size: float | list = 3.0, show_legend: bool = True, legend_kwargs: dict | None = None, show_outline: bool = False, outline_kwargs: dict | None = None, text: str | list = None, text_kwargs: dict | None = None, view_up: tuple = (0.5, 0.5, 1), framerate: int = 24, plotter_filename: str | None = None)[source]#

Multi-view visualization of reconstructed 3D model. If you want to draw a legend in each sub-window, please ensure that the key names used in each legend are different.

Parameters:
model

A MultiBlock of reconstructed models or a reconstructed model.

key

The key under which are the labels.

filename

Filename of output file. Writer type is inferred from the extension of the filename.

  • Output an image file,please enter a filename ending with '.png', '.tif', '.tiff', '.bmp', '.jpeg', '.jpg', '.svg', '.eps', '.ps', '.pdf', '.tex'.

  • Output a gif file, please enter a filename ending with .gif.

  • Output a mp4 file, please enter a filename ending with .mp4.

jupyter

Whether to plot in jupyter notebook. Available jupyter are:

  • 'none' - Do not display in the notebook.

  • 'pythreejs' - Show a pythreejs widget

  • 'static' - Display a static figure.

  • 'ipygany' - Show an ipygany widget

  • 'panel' - Show a panel widget.

off_screen

Renders off-screen when True. Useful for automated screenshots.

shape

Number of sub-render windows inside the main window. By default, there is only one render window.

  • Specify two across with ``shape``=(2, 1) and a two by two grid with ``shape``=(2, 2).

  • shape Can also accept a string descriptor as shape.

    E.g.: shape="3|1" means 3 plots on the left and 1 on the right, E.g.: shape="4/2" means 4 plots on top and 2 at the bottom.

window_size

Window size in pixels. The default window_size is [512, 512].

background

The background color of the window.

cpo

Camera position of the active render window. Available cpo are:

  • Iterable containing position, focal_point, and view up.

    E.g.: [(2.0, 5.0, 13.0), (0.0, 0.0, 0.0), (-0.7, -0.5, 0.3)].

  • Iterable containing a view vector.

    E.g.: [-1.0, 2.0, -5.0].

  • A string containing the plane orthogonal to the view direction.

    E.g.: 'xy', 'xz', 'yz', 'yx', 'zx', 'zy', 'iso'.

colormap

Name of the Matplotlib colormap to use when mapping the scalars.

When the colormap is None, use {key}_rgba to map the scalars, otherwise use the colormap to map scalars.

ambient

When lighting is enabled, this is the amount of light in the range of 0 to 1 (default 0.0) that reaches the actor when not directed at the light source emitted from the viewer.

opacity

Opacity of the model.

If a single float value is given, it will be the global opacity of the model and uniformly applied everywhere, elif a numpy.ndarray with single float values is given, it will be the opacity of each point. - should be between 0 and 1.

A string can also be specified to map the scalars range to a predefined opacity transfer function (options include: ‘linear’, ‘linear_r’, ‘geom’, ‘geom_r’).

model_style

Visualization style of the model. One of the following:

  • model_style = 'surface',

  • model_style = 'wireframe',

  • model_style = 'points'.

model_size

If model_style = 'points', point size of any nodes in the dataset plotted.

If model_style = 'wireframe', thickness of lines.

show_legend

whether to add a legend to the plotter.

legend_kwargs

A dictionary that will be pass to the add_legend function. By default, it is an empty dictionary and the add_legend function will use the {"legend_size": None, "legend_loc": None,  "legend_size": None, "legend_loc": None, "title_font_size": None, "label_font_size": None, "font_family": "arial", "fmt": "%.2e", "n_labels": 5, "vertical": True} as its parameters. Otherwise, you can provide a dictionary that properly modify those keys according to your needs.

show_outline

whether to produce an outline of the full extent for the model.

outline_kwargs

A dictionary that will be pass to the add_outline function.

By default, it is an empty dictionary and the add_legend function will use the {"outline_width": 5.0, "outline_color": "black", "show_labels": True, "font_size": 16, "font_color": "white", "font_family": "arial"} as its parameters. Otherwise, you can provide a dictionary that properly modify those keys according to your needs.

text

The text to add the rendering.

text_kwargs

A dictionary that will be pass to the add_text function.

By default, it is an empty dictionary and the add_legend function will use the { "font_family": "arial", "font_size": 12, "font_color": "black", "text_loc": "upper_left"} as its parameters. Otherwise, you can provide a dictionary that properly modify those keys according to your needs.

view_up

The normal to the orbital plane. Only available when filename ending with .mp4 or .gif.

framerate

Frames per second. Only available when filename ending with .mp4 or .gif.

plotter_filename

The filename of the file where the plotter is saved.

Writer type is inferred from the extension of the filename.

  • Output a gltf file, please enter a filename ending with .gltf.

  • Output a html file, please enter a filename ending with .html.

  • Output an obj file, please enter a filename ending with .obj.

  • Output a vtkjs file, please enter a filename without format.

spateo.plotting.static.three_d_plot(model: pyvista.PolyData | pyvista.UnstructuredGrid | pyvista.MultiBlock, key: str | list = None, filename: str | None = None, jupyter: bool | Literal[panel, none, pythreejs, static, ipygany] = False, off_screen: bool = False, window_size: tuple = (512, 512), background: str = 'white', cpo: str | list = 'iso', colormap: str | list | None = None, ambient: float | list = 0.2, opacity: float | numpy.ndarray | list = 1.0, model_style: Literal[points, surface, wireframe] | list = 'surface', model_size: float | list = 3.0, show_legend: bool = True, legend_kwargs: dict | None = None, show_outline: bool = False, outline_kwargs: dict | None = None, text: str | None = None, text_kwargs: dict | None = None, view_up: tuple = (0.5, 0.5, 1), framerate: int = 24, plotter_filename: str | None = None)#

Visualize reconstructed 3D model.

Parameters:
model

A reconstructed model.

key

The key under which are the labels.

filename

Filename of output file. Writer type is inferred from the extension of the filename.

  • Output an image file,please enter a filename ending with '.png', '.tif', '.tiff', '.bmp', '.jpeg', '.jpg', '.svg', '.eps', '.ps', '.pdf', '.tex'.

  • Output a gif file, please enter a filename ending with .gif.

  • Output a mp4 file, please enter a filename ending with .mp4.

jupyter

Whether to plot in jupyter notebook. Available jupyter are:

  • 'none' - Do not display in the notebook.

  • 'pythreejs' - Show a pythreejs widget

  • 'static' - Display a static figure.

  • 'ipygany' - Show an ipygany widget

  • 'panel' - Show a panel widget.

off_screen

Renders off-screen when True. Useful for automated screenshots.

window_size

Window size in pixels. The default window_size is [512, 512].

background

The background color of the window.

cpo

Camera position of the active render window. Available cpo are:

  • Iterable containing position, focal_point, and view up.

    E.g.: [(2.0, 5.0, 13.0), (0.0, 0.0, 0.0), (-0.7, -0.5, 0.3)].

  • Iterable containing a view vector.

    E.g.: [-1.0, 2.0, -5.0].

  • A string containing the plane orthogonal to the view direction.

    E.g.: 'xy', 'xz', 'yz', 'yx', 'zx', 'zy', 'iso'.

colormap

Name of the Matplotlib colormap to use when mapping the scalars.

When the colormap is None, use {key}_rgba to map the scalars, otherwise use the colormap to map scalars.

ambient

When lighting is enabled, this is the amount of light in the range of 0 to 1 (default 0.0) that reaches the actor when not directed at the light source emitted from the viewer.

opacity

Opacity of the model.

If a single float value is given, it will be the global opacity of the model and uniformly applied everywhere, elif a numpy.ndarray with single float values is given, it will be the opacity of each point. - should be between 0 and 1.

A string can also be specified to map the scalars range to a predefined opacity transfer function (options include: ‘linear’, ‘linear_r’, ‘geom’, ‘geom_r’).

model_style

Visualization style of the model. One of the following:

  • model_style = 'surface',

  • model_style = 'wireframe',

  • model_style = 'points'.

model_size

If model_style = 'points', point size of any nodes in the dataset plotted.

If model_style = 'wireframe', thickness of lines.

show_legend

whether to add a legend to the plotter.

legend_kwargs

A dictionary that will be pass to the add_legend function. By default, it is an empty dictionary and the add_legend function will use the {"legend_size": None, "legend_loc": None,  "legend_size": None, "legend_loc": None, "title_font_size": None, "label_font_size": None, "font_family": "arial", "fmt": "%.2e", "n_labels": 5, "vertical": True} as its parameters. Otherwise, you can provide a dictionary that properly modify those keys according to your needs.

show_outline

whether to produce an outline of the full extent for the model.

outline_kwargs

A dictionary that will be pass to the add_outline function.

By default, it is an empty dictionary and the add_legend function will use the {"outline_width": 5.0, "outline_color": "black", "show_labels": True, "font_size": 16, "font_color": "white", "font_family": "arial"} as its parameters. Otherwise, you can provide a dictionary that properly modify those keys according to your needs.

text

The text to add the rendering.

text_kwargs

A dictionary that will be pass to the add_text function.

By default, it is an empty dictionary and the add_legend function will use the { "font_family": "arial", "font_size": 12, "font_color": "black", "text_loc": "upper_left"} as its parameters. Otherwise, you can provide a dictionary that properly modify those keys according to your needs.

view_up

The normal to the orbital plane. Only available when filename ending with .mp4 or .gif.

framerate

Frames per second. Only available when filename ending with .mp4 or .gif.

plotter_filename

The filename of the file where the plotter is saved.

Writer type is inferred from the extension of the filename.

  • Output a gltf file, please enter a filename ending with .gltf.

  • Output a html file, please enter a filename ending with .html.

  • Output an obj file, please enter a filename ending with .obj.

  • Output a vtkjs file, please enter a filename without format.

Returns:

List of camera position, focal point, and view up.

Returned only if filename is None or filename ending with '.png', '.tif', '.tiff', '.bmp', '.jpeg', '.jpg', '.svg', '.eps', '.ps', '.pdf', '.tex'.

img: Numpy array of the last image.

Returned only if filename is None or filename ending with '.png', '.tif', '.tiff', '.bmp', '.jpeg', '.jpg', '.svg', '.eps', '.ps', '.pdf', '.tex'.

Return type:

cpo

spateo.plotting.static.torsion(adata: anndata.AnnData, model: pyvista.PolyData | pyvista.UnstructuredGrid | pyvista.MultiBlock | list, torsion_key: str = 'torsion', filename: str | None = None, jupyter: bool | Literal[none, static, trame] = False, colormap: str | list | None = 'default_cmap', ambient: float | list = 0.2, opacity: float | numpy.ndarray | list = 1.0, model_style: Literal[points, surface, wireframe] | list = 'points', model_size: float | list = 3.0, **kwargs)[source]#

Visualize the torsion result.

Parameters:
adata

An anndata object contain torsion values in .obs[torsion_key].

model

A reconstructed model contains obs_index values.

torsion_key

The key in .obs that corresponds to the torsion values in the anndata object.

filename

Filename of output file. Writer type is inferred from the extension of the filename.

  • Output an image file,please enter a filename ending with '.png', '.tif', '.tiff', '.bmp', '.jpeg', '.jpg', '.svg', '.eps', '.ps', '.pdf', '.tex'. When jupyter=False, if you want to save ‘.png’ file, please ensure off_screen=True.

  • Output a gif file, please enter a filename ending with .gif.

  • Output a mp4 file, please enter a filename ending with .mp4.

jupyter

Whether to plot in jupyter notebook. Available jupyter are:

  • 'none' - Do not display in the notebook.

  • 'trame' - Show a trame widget

  • 'static' - Display a static figure.

colormap

Name of the Matplotlib colormap to use when mapping the scalars.

When the colormap is None, use {key}_rgba to map the scalars, otherwise use the colormap to map scalars.

ambient

When lighting is enabled, this is the amount of light in the range of 0 to 1 (default 0.0) that reaches the actor when not directed at the light source emitted from the viewer.

opacity

Opacity of the model.

If a single float value is given, it will be the global opacity of the model and uniformly applied everywhere, elif a numpy.ndarray with single float values is given, it will be the opacity of each point. - should be between 0 and 1.

A string can also be specified to map the scalars range to a predefined opacity transfer function (options include: ‘linear’, ‘linear_r’, ‘geom’, ‘geom_r’).

model_style

Visualization style of the model. One of the following:

  • model_style = 'surface',

  • model_style = 'wireframe',

  • model_style = 'points'.

model_size

If model_style = 'points', point size of any nodes in the dataset plotted.

If model_style = 'wireframe', thickness of lines.

**kwargs

Additional parameters that will be passed into the st.pl.feature function.

Returns:

List of camera position, focal point, and view up.

Returned only if filename is None or filename ending with '.png', '.tif', '.tiff', '.bmp', '.jpeg', '.jpg', '.svg', '.eps', '.ps', '.pdf', '.tex'.

img: Numpy array of the last image.

Returned only if filename is None or filename ending with '.png', '.tif', '.tiff', '.bmp', '.jpeg', '.jpg', '.svg', '.eps', '.ps', '.pdf', '.tex'.

Return type:

cpo

Examples

Visualize only in one model:

st.pl.torsion(

adata=stage_adata, model=stage_pc, torsion_key=”torsion”, jupyter=”static”, model_style=”points”, model_size=3

)

Visualize in multiple model:

st.pl.torsion(

adata=stage_adata, model=[stage_pc, trajectory_model], torsion_key=”torsion”, jupyter=”static”, model_style=[“points”, “wireframe”], model_size=[3, 1]

)