- spac.visualization._plot_spatial_distance_dispatch(df_long, method, plot_type, stratify_by=None, facet_plot=False, **kwargs)[source]
Decides the figure layout based on ‘stratify_by’ and ‘facet_plot’ and dispatches actual plotting calls.
- Logic:
If stratify_by and facet_plot => single figure with subplots (faceted)
If stratify_by and not facet_plot => multiple figures, one per group
If stratify_by is None => single figure (no subplots)
This function calls seaborn figure-level functions (catplot or displot).
- Parameters:
df_long (pd.DataFrame) – Tidy DataFrame with columns [‘cellid’, ‘group’, ‘distance’, ‘phenotype’, ‘stratify_by’].
method ({'numeric', 'distribution'}) – Determines which seaborn function is used (catplot or displot).
plot_type (str) – For method=’numeric’: ‘box’, ‘violin’, ‘boxen’, etc. For method=’distribution’: ‘hist’, ‘kde’, ‘ecdf’, etc.
stratify_by (str or None) – Column name for grouping. If None, no grouping is done.
facet_plot (bool) – If True, subplots in a single figure (faceted). If False, separate figures (one per group) or a single figure.
**kwargs – Additional seaborn plotting arguments (e.g., col_wrap=2).
- Returns:
- Dictionary with two keys:
”data”: the DataFrame (df_long)
”fig”: a Matplotlib Figure or a list of Figures
- Return type:
dict
- Raises:
ValueError – If ‘method’ is invalid (not ‘numeric’ or ‘distribution’).
Examples
Called internally by ‘visualize_nearest_neighbor’. Typically not used directly by end users.