, basis, key, *, group='all', color_map='YlOrRd', bg_dotsize=80, fg_dotsize=180, vmax=1, vmin=0, ncols=4, hspace=0.25, wspace=None, save=None, show=None, **kwargs)

Plot the density of cells in an embedding (per condition)

Plots the gaussian kernel density estimates (over condition) from the output.

This function was written by Sophie Tritschler and implemented into Scanpy by Malte Luecken.

adata : AnnDataAnnData

The annotated data matrix.

basis : strstr

The embedding over which the density was calculated. This embedded representation should be found in adata.obsm['X_[basis]']`.

key : strstr

Name of the .obs covariate that contains the density estimates

group : str, List[str], NoneUnion[str, List[str], None]

The category in the categorical observation annotation to be plotted. For example, ‘G1’ in the cell cycle ‘phase’ covariate. If all categories are to be plotted use group=’all’ (default), If multiple categories want to be plotted use a list (e.g.: [‘G1’, ‘S’]. If the overall density wants to be ploted set group to ‘None’.

color_map : Colormap, strUnion[Colormap, str]

Matplolib color map to use for density plotting.

bg_dotsize : int, NoneOptional[int]

Dot size for background data points not in the group.

fg_dotsize : int, NoneOptional[int]

Dot size for foreground data points in the group.

vmax : int, NoneOptional[int]

Density that corresponds to color bar maximum.

vmin : int, NoneOptional[int]

Density that corresponds to color bar minimum.

ncols : int, NoneOptional[int]

Number of panels per row.

wspace : NoneNone

Adjust the width of the space between multiple panels.

hspace : float, NoneOptional[float]

Adjust the height of the space between multiple panels.

show : bool, NoneOptional[bool]

Show the plot, do not return axis.

save : bool, str, NoneUnion[bool, str, None]

If True or a str, save the figure. A string is appended to the default filename. Infer the filetype if ending on {‘.pdf’, ‘.png’, ‘.svg’}.


A matplotlib axes object. Only works if plotting a single component.


>>> adata = sc.datasets.pbmc68k_reduced()
>>>, basis='umap', groupby='phase')

Plot all categories be default >>>, basis=’umap’, key=’umap_density_phase’)

Plot selected categories >>>, basis=’umap’, key=’umap_density_phase’, … group=[‘G1’, ‘S’])