metachat.pl.plot_dis_thr
- metachat.pl.plot_dis_thr(adata, dis_thr, spot_index, use_existing_distance=False, figsize=(6, 5), ax=None, plot_savepath=None)[source]
Visualize spatial neighborhood within a specified distance threshold around a selected spot.
This function highlights which spots in the spatial omics dataset fall within a given Euclidean distance (dis_thr) from a selected spot. The center spot is shown in a distinct color, while neighboring and non-neighboring spots are visually separated.
Parameters
- adataanndata.AnnData
Annotated data matrix containing spatial coordinates in
adata.obsm["spatial"].- dis_thrfloat
Distance threshold (in pixel or micron units, depending on
adatascaling) used to define spatial neighbors.- spot_indexint
Index (0-based) of the reference/center spot.
- use_existing_distancebool, default=False
Whether to reuse an existing precomputed distance matrix stored in
adata.obsp["spatial_distance"]. If False, a new Euclidean distance matrix will be computed.- figsizetuple of float, default=(6, 5)
Figure size (width, height) in inches.
- axmatplotlib.axes.Axes, optional
Existing Matplotlib axis to draw on. If None, a new figure and axis are created.
- plot_savepathstr, optional
File path to save the plot (e.g.,
"results/dis_thr_spots.pdf"). The format is inferred from the file extension. If None, the plot is shown interactively.
Returns
- axmatplotlib.axes.Axes
Matplotlib axis containing the rendered spatial scatter plot.
Notes
This function helps visualize local spot neighborhoods used in spatial communication or proximity-based analyses (e.g., for barrier-aware OT or diffusion modeling).
- The color coding is:
center – the selected reference spot
neighbor – spots within dis_thr distance
outside – all other spots