metachat.pl.plot_spot_distance

metachat.pl.plot_spot_distance(adata, dist_matrix_key, spot_index, figsize=(6, 5), ax=None, plot_savepath=None)[source]

Visualize the spatial distance from a selected spot to all other spots.

This function displays the distance values (from a specified spot) stored in a precomputed distance matrix under adata.obsp. It helps assess local or long-range connectivity patterns in spatial data.

Parameters

adataanndata.AnnData

Annotated data matrix containing spatial coordinates in adata.obsm["spatial"] and a distance matrix stored in adata.obsp.

dist_matrix_keystr

Key name in adata.obsp where the spatial distance matrix is stored, e.g., "spatial_distance" or "spatial_distance_LRC_base".

spot_indexint

Index of the target spot (0-based) whose distances to all other spots will be visualized.

figsizetuple of float, default=(6, 5)

Figure size (width, height) in inches.

plot_savepathstr, optional

Path to save the plot (e.g. "results/distance_to_spot120.pdf"). The format is inferred from the file extension. If None, the figure is shown interactively.

axmatplotlib.axes.Axes, optional

Existing Matplotlib axis to draw the plot on. If None, a new figure and axis will be created.

Returns

axmatplotlib.axes.Axes

Matplotlib axis containing the rendered spatial distance visualization.

Notes

  • Distances are taken directly from the precomputed matrix in adata.obsp.

  • The distances are stored in adata.obs["distance_from_target"] for plotting.

  • The selected target spot (by index) can be visually identified as having the minimum distance (0).