_plot_spatial_distance_dispatch

spac.visualization._plot_spatial_distance_dispatch(df_long, method, plot_type, stratify_by=None, facet_plot=False, distance_col='distance', hue_axis='group', palette=None, **kwargs)[source]

Dispatch a seaborn call to visualise nearest-neighbor distances. Returns Axes object(s) for further customization.

Layout logic

  1. stratify_by & facet_plot → Faceted plot, returns Axes or List[Axes] for the “ax” key.

  2. stratify_by & not facet_plot → List of plots, returns List[Axes] for the “ax” key.

  3. stratify_by is None → Single plot, returns Axes or List[Axes] (if plot_type creates facets) for the “ax” key.

param df_long:

Tidy DataFrame returned by _prepare_spatial_distance_data with a long layout and with columns [‘cellid’, ‘group’, ‘distance’, ‘phenotype’, ‘stratify_by’].

type df_long:

pd.DataFrame

param method:

'numeric':pyfunc:`seaborn.catplot` 'distribution':pyfunc:`seaborn.displot`

type method:

{‘numeric’, ‘distribution’}

param plot_type:

Kind forwarded to Seaborn. Numeric (method=’numeric’) – box, violin, boxen, strip, swarm, etc. Distribution (method=’distribution’) – hist, kde, ecdf, etc.

type plot_type:

str

param stratify_by:

Column used to split data. None for no splitting.

type stratify_by:

str or None

param facet_plot:

If True with stratify_by, create a faceted grid, otherwise returns individual axes.

type facet_plot:

bool, default False

param distance_col:

Column name in df_long holding the numeric distance values. ‘distance’ – raw Euclidean / pixel / micron distances. ‘log_distance’ – natural-log‐transformed distances. The axis label is automatically adjusted.

type distance_col:

str, default ‘distance’

param hue_axis:

Column that encodes the hue (color) dimension.

type hue_axis:

str, default ‘group’

param palette:
  • dict → color map forwarded to seaborn/Matpotlib.

  • str → any Seaborn/Matplotlib palette name

  • None → defaults chosen by Seaborn

Typically the pin‑color map prepared upstream.

type palette:

dict or str or None

param **kwargs:

Extra keyword args propagated to Seaborn. Legend control (e.g. legend=False) should be passed here if needed.

returns:
{

‘data’: pandas.DataFrame, # the input df_long ‘ax’ : matplotlib.axes.Axes | list[Axes]

}

rtype:

dict