Plotting functions for spatial geometry plots.

Module Contents#


geo(adata[, basis, color, genes, gene_cmaps, dpi, ...])

Geometry plot for physical coordinates of each cell.

space_polygons(polygons_path, adata[, color, fov])

Plot polygons on spatial coordinates.


Process cell data to construct contours and calculate area and centroid.

spateo.plotting.static.geo.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)[source]#

Geometry plot for physical coordinates of each cell.


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


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


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.


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.


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


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:


The alpha value of the cells.


The line width of boundary.


The color value of boundary.


whether to show all gene plots on the same plot


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


control the size of legend when stacking genes


size of the figure.


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:


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


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.geo.space_polygons(polygons_path: str, adata: anndata.AnnData, color: List[str] | str | None = None, fov: int | str | None = None, **kwargs)[source]#

Plot polygons on spatial coordinates.


The path to the file containing polygon coordinates


The AnnData object that contains the spatial coordinates, gene expression, cell type labels, etc.


The column name in the adata.obs that will be used to color the polygons.


The fov name that will be used to select the polygons. If None, all polygons will be plotted.


Additional arguments passed to :func ~``.

spateo.plotting.static.geo.create_polygon_object_nanostring(polygon_df: pandas.DataFrame)[source]#

Process cell data to construct contours and calculate area and centroid.


Input DataFrame containing pixel-to-cell correspondence data with columns ‘cellID_fov’, ‘x_local_px’, and ‘y_local_px’.


Dataframe containing polygon information. Contains columns ‘label’, ‘area’, ‘bbox-0’,

’bbox-1’, ‘bbox-2’, ‘bbox-3’, ‘centroid-0’, ‘centroid-1’, and ‘contour’. Indexed by the ‘label’ column.

Return type: