spateo.plotting.static.space

Functions

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

Scatter plot for physical coordinates of each cell.

plot_cell_signaling(adata, vf_key[, geo, color, ...])

After inferring directionality of effects for models that consider ligand expression (:attr mod_type is

Module Contents

spateo.plotting.static.space.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.space.plot_cell_signaling(adata: anndata.AnnData, vf_key: str, geo: bool = False, color: List[str] | str | None | None = None, arrow_color: str = 'tab:blue', edgewidth: float = 0.2, genes: List[str] = [], gene_cmaps=None, space: str = 'spatial', width: float = 6, marker: str = '.', basis: str = 'contour', boundary_width: float = 0.2, boundary_color: str = 'black', pointsize: float | None = None, dpi: int = 100, ps_sample_num: int = 1000, alpha: float = 0.8, plot_method: Literal['cell', 'grid', 'stream'] = 'cell', scale: float | None = None, scale_units: Literal['width', 'height', 'dots', 'inches', 'x', 'y', 'xy'] | None = None, grid_density: float = 1, grid_knn: int | None = None, grid_scale: float = 1.0, grid_threshold: float = 1.0, grid_width: float | None = None, stream_density: float | None = None, stream_linewidth: float | None = None, stream_cutoff_percentile: float = 5, figsize: Tuple[float, float] | None = None, *args, **kwargs)[source]

After inferring directionality of effects for models that consider ligand expression (:attr mod_type is ‘ligand’ or ‘lr’, this can be used to visualize the inferred directionality in the form of a vector field plot. Note: currently incompatible with datashader.

Parts of this function are inspired by ‘plot_cell_signaling’ from COMMOT: https://github.com/zcang/COMMOT

Parameters:
adata

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

vf_key

Key in .obsm where the vector field is stored

geo

Whether to plot the vector field on top of a geometry plot rather than a scatter plot of cells. Note that none of the pointsize arguments (e.g. ‘pointsize’, ‘ps_sample_num’) will be used if this is True.

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.

arrow_color

Sets color of vector field arrows

edgewidth

Sets width of vector field arrows. Recommended 0.1-0.3.

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.

genes_cmaps

Optional color map for each gene.

space

The key to spatial coordinates

alpha

The alpha value of the scatter points. Recommended 0.5-0.7.

width

Width of the figure

marker

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

basis

Only used if geo is True. The key to the column in adata.obs from which the contour of the cell segmentation will be generated.

boundary_width

Only used if geo is True. The width of the contour lines.

boundary_color

Only used if geo is True. The color of the contour lines.

pointsize

The size of the points on the scatter plot. Not used if ‘geo’ is True.

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

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.

scale

The scale parameter passed to :func matplotlib.pyplot.quiver for vector field plots. The smaller the value, the longer the arrows. Recommended ~0.01.

grid_density

Only used if ‘to_plot’ is ‘grid’. The density of the grid points used to estimate the vector field. The larger the value, the more grid points there will be.

grid_knn

Only used if ‘to_plot’ is ‘grid’. The number of nearest neighbors used to interpolate the signaling directions from spots to grid points.

grid_scale

Only used if ‘to_plot’ is ‘grid’. The scale parameter for the kernel function used to map directions of spots to grid points.

grid_threshold

Only used if ‘to_plot’ is ‘grid’. The threshold forinterpolation weights, used to determine whether to include a grid point. Smaller values give tighter coverage of the tissue by the grid points.

grid_width

Only used if ‘to_plot’ is ‘grid’. The width of the vector lines. Recommended on the order of 0.005.

stream_density

Only used if ‘to_plot’ is ‘stream’. The density of the stream lines passed to :func matplotlib.pyplot.streamplot.

stream_linewidth

Only used if ‘to_plot’ is ‘stream’. The width of the stream lines passed to :func matplotlib.pyplot.streamplot.

stream_cutoff_percentile

Only used if ‘to_plot’ is ‘stream’. The percentile of the vector field magnitude used to determine if/which vectors are plotted or not. Defaults to 5, meaning that vectors shorter than the 5% quantile will not be plotted.