metachat.pl.plot_communication_flow

metachat.pl.plot_communication_flow(adata, database_name, metabolite_name=None, metapathway_name=None, customerlist_name=None, ms_pair_name=None, summary='receiver', plot_method='grid', background='image', library_id=None, group_name=None, group_cmap=None, background_legend=False, cmap='coolwarm', pos_idx=array([0, 1]), normalize_summary_quantile=0.995, ndsize=3, vmin=None, vmax=None, grid_density=1.0, grid_knn=None, grid_scale=1.0, grid_thresh=1.0, arrow_color='#000000', arrow_width=0.005, largest_arrow=0.05, normalize_v=False, normalize_v_quantile=0.95, title=None, plot_savepath=None, ax=None)[source]

Visualize inferred metabolic communication vector fields on tissue images or annotated backgrounds.

This function overlays communication flow vectors computed from MetaChat analysis results on tissue images, categorical annotations, or summary backgrounds. It supports spot-wise, grid-interpolated, or streamline rendering.

Parameters

adataanndata.AnnData

Annotated data matrix containing spatial coordinates in adata.obsm["spatial"].

database_namestr

Name of the metabolite–sensor interaction database used for communication inference.

metabolite_namestr, optional

Name of a specific metabolite to visualize. Mutually exclusive with metapathway_name, customerlist_name, and ms_pair_name.

metapathway_namestr, optional

Name of a specific metabolic pathway to visualize.

customerlist_namestr, optional

Name of a custom metabolite–sensor list to visualize.

ms_pair_namestr, optional

Name of a metabolite–sensor pair to visualize.

summary{“sender”, “receiver”}, default=”receiver”

Type of summary statistic used for background coloring.

plot_method{“cell”, “grid”, “stream”}, default=”grid”

Rendering mode for vector visualization.

background{“summary”, “image”, “group”}, default=”image”

Type of background to draw behind the vectors.

library_idstr, optional

Visium library identifier used when background="image".

group_namestr, optional

Column in adata.obs used for categorical coloring when background="group".

group_cmapdict, optional

Mapping from category names to colors.

background_legendbool, default=False

Whether to display legend for the background.

cmapstr, default=”coolwarm”

Colormap name for summary or numeric backgrounds.

pos_idxnp.ndarray, default=np.array([0,1])

Indices of spatial coordinates used for plotting.

normalize_summary_quantilefloat, default=0.995

Quantile for clipping background values.

ndsizefloat, default=3

Spot marker size.

vmin, vmaxfloat, optional

Color scale limits for background values.

grid_densityfloat, default=1.0

Density of interpolation grid when plot_method="grid".

grid_knnint, optional

Number of neighbors used for vector interpolation.

grid_scalefloat, default=1.0

Kernel scale factor for interpolation.

grid_threshfloat, default=1.0

Minimum interpolation weight threshold.

arrow_colorstr, default=”#000000”

Color of flow arrows.

arrow_widthfloat, default=0.005

Width of quiver arrows.

largest_arrowfloat, default=0.05

Maximum arrow length after normalization.

normalize_vbool, default=False

Whether to normalize vector magnitudes for visualization.

normalize_v_quantilefloat, default=0.95

Quantile for magnitude clipping before normalization.

titlestr, optional

Title of the plot.

plot_savepathstr, optional

File path to save the plot; no saving if None.

axmatplotlib.axes.Axes, optional

Axis to draw the plot on; creates new one if None.

Returns

axmatplotlib.axes.Axes

Matplotlib axis containing the resulting plot.

coords_plotnp.ndarray

Coordinates used for plotting (after interpolation).

V_plotnp.ndarray

Vector field used for plotting (after interpolation).