c2v.pl.group_kde

Contents

c2v.pl.group_kde#

c2v.pl.group_kde(adata, groupby, groups=None, basis='X_umap', bw_method=0.15, ncols=4, frameon=False, square=True, ax=None, return_fig=False, cmap='Reds', title=None, kwargs=None, show=True, figsize=None)#

Plots kernel density estimates (KDE) of cells from one or multiple groups on a 2D embedding.

Uses scipy.stats.gaussian_kde to estimate density of a group and overlays it as a contour plot.

Parameters:
adata AnnData

AnnData object containing embeddings and group annotations.

groupby str

Column in adata.obs used to identify cell groups.

groups list[str] | str | None

Specific group(s) to visualize.

basis str, optional

Embedding key from adata.obsm to use. Default is “X_umap”.

bw_method list[float | str] | float | str, optional

Bandwidth for the KDE. Passed to scipy.stats.gaussian_kde. Can be a single value or a list per group. Default is 0.1.

ncols int, optional

Number of columns in the subplot grid when plotting multiple groups. Default is 4.

square bool, optional

Whether to set the aspect ratio of the plot to be equal. Default is True.

frameon list[bool] | bool, optional

Whether to show axes frame for each subplot. Can be a single bool or a list per group. Default is False.

ax matplotlib.axes.Axes | list[matplotlib.axes.Axes] | None, optional

Axes object(s) to draw the plot on. If None, a new figure/grid is created.

return_fig bool, optional

If True, returns the Matplotlib Figure object. Default is False.

cmap list[ColorMap | str] | ColorMap | str, optional

Colormap(s) to use for KDE overlay. Can be a single value or a list per group. Default is “Reds”.

title list[str] | str | None, optional

Plot title(s). If None, uses “{group} KDE”.

kwargs list[dict] | dict | None, optional

Additional arguments passed to sc.pl.embedding for the background. Can be a single dict or a list per group.

show bool, optional

Whether to show the plot. Default is True.

figsize tuple[float, float] | None, optional

Figure size. Default is None.

Return type:

Figure | Axes | ndarray | list[Axes] | None

Returns:

None | matplotlib.figure.Figure | matplotlib.axes.Axes | np.ndarray | list[matplotlib.axes.Axes] Returns Figure if return_fig is True; otherwise returns None or axes.