Skip to content

spatialDistanceDistribution

spatialDistanceDistribution

spatialDistanceDistribution(
    data,
    spatialDistance="spatial_distance",
    phenotype="phenotype",
    imageId="imageid",
    distanceFrom=None,
    distanceTo=None,
    xAxis=None,
    yAxis=None,
    facetBy=None,
    plotType=None,
    subsetCol=None,
    subsetValue=None,
    fileName="spatial_distance_distribution.pdf",
    outputDir=None,
    saveDir=None,
    show=True,
    returnData=False,
    returnFig=False,
    dpi=300,
    transparent=False,
    sdataTable=None,
    **kwargs
)

Distance distributions as box plots, one box per target cell type.

The heatmap shows means; this shows the spread behind them, which is where bimodality and long tails become visible. Built by melting the per-cell distance table into long form.

Parameters:

Name Type Description Default
data (AnnData | SpatialData | str, required)

The cell table. An AnnData, a path to an .h5ad file, a SpatialData object, or a path to a .zarr SpatialData store.

required
spatialDistance str

Key in uns holding the distance table.

'spatial_distance'
phenotype str

Column in obs holding the source cell types.

'phenotype'
imageId str

Column in obs holding image identifiers.

'imageid'
distanceFrom str | list

Keep only cells of these phenotypes — the cell types you measure from.

None
distanceTo str | list

Keep only these target columns — the cell types you measure to.

None
xAxis str

Accepted for signature compatibility with scimap; the x axis is always the target cell type.

None
yAxis str

Accepted for signature compatibility with scimap; the y axis is always distance.

None
facetBy str

Accepted for signature compatibility with scimap; the current implementation draws a single panel. Use subsetCol and subsetValue to plot one facet at a time.

None
plotType str

Accepted for signature compatibility with scimap; box plots are drawn.

None
subsetCol str

Column in obs to filter on before plotting.

None
subsetValue str | list

Values of subsetCol to keep.

None
**kwargs dict

Extra options. figsize sets the figure size in inches.

{}
fileName str

File name for the saved figure. The extension decides the format.

'spatial_distance_distribution.pdf'
outputDir str

Directory to save the figure in. When None nothing is written.

None
saveDir str

Deprecated alias for outputDir, kept for scripts carried over from scimap. outputDir wins when both are given.

None
show bool

Call plt.show() before returning. Set False in scripts and notebooks that save rather than display.

True
returnData bool

Return the DataFrame behind the plot instead of drawing it.

False
returnFig bool

Return (fig, axes). With returnData as well, returns (fig, axes, plotData).

False
dpi int

Resolution of the saved figure.

300
transparent bool

Save with a transparent background.

False
sdataTable str

Which SpatialData table to read. Ignored for AnnData input, and optional when the store has exactly one table.

None

Returns:

Name Type Description
result None | DataFrame | tuple

None by default; the long-form DataFrame (phenotype, image id, distanceTo, distance) with returnData=True; (fig, ax) with returnFig=True.

Example
adata = sp.tl.spatialDistance(adata, phenotype="phenotype")
sp.pl.spatialDistanceDistribution(adata, distanceFrom="Treg")