cellrank.pl.heatmap(adata, model, genes, lineages=None, backward=False, mode=HeatmapMode.LINEAGES, time_key='latent_time', time_range=None, callback=None, cluster_key=None, show_absorption_probabilities=False, cluster_genes=False, keep_gene_order=False, scale=True, n_convolve=5, show_all_genes=False, cbar=True, lineage_height=0.33, fontsize=None, xlabel=None, cmap=<matplotlib.colors.ListedColormap object>, dendrogram=True, return_genes=False, return_models=False, return_figure=False, n_jobs=1, backend='loky', show_progress_bar=True, figsize=None, dpi=None, save=None, **kwargs)[source]#

Plot a heatmap of smoothed gene expression along specified lineages.

  • adata (anndata.AnnData) – Annotated data object.

  • model (Union[BaseModel, Mapping[str, Mapping[str, BaseModel]]]) –

    Model based on cellrank.models.BaseModel to fit.

    If a dict, gene and lineage specific models can be specified. Use '*' to indicate all genes or lineages, for example {'gene_1': {'*': ...}, 'gene_2': {'lineage_1': ..., '*': ...}}.

  • genes (Sequence[str]) – Genes in anndata.AnnData.var_names or in anndata.AnnData.raw.var_names, if use_raw = True.

  • lineages (Union[str, Sequence[str], None]) – Names of the lineages for which to plot. If None, plot all lineages.

  • backward (bool) – Direction of the process.

  • mode (Literal[‘genes’, ‘lineages’]) –

    Valid options are:

    • ’lineages’ - group by genes for each lineage in lineages.

    • ’genes’ - group by lineages for each gene in genes.

  • time_key (str) – Key in attr:anndata.AnnData.obs where the pseudotime is stored.

  • time_range (Union[float, Tuple[Optional[float], Optional[float]], None, List[Union[float, Tuple[Optional[float], Optional[float]], None]]]) –

    Specify start and end times:

    • If a tuple, it specifies the minimum and maximum pseudotime. Both values can be None, in which case the minimum is the earliest pseudotime and the maximum is automatically determined.

    • If a float, it specifies the maximum pseudotime.

    This can also be specified on per-lineage basis.

  • gene_symbols – Key in anndata.AnnData.var to use instead of anndata.AnnData.var_names.

  • callback (Union[Callable, Mapping[str, Mapping[str, Callable]], None]) – Function which takes a cellrank.models.BaseModel and some keyword arguments for cellrank.models.BaseModel.prepare() and returns the prepared model. Can be specified in gene- and lineage-specific manner, similarly to model.

  • cluster_key (Union[str, Sequence[str], None]) – Key(s) in anndata.AnnData.obs containing categorical observations to be plotted on the top of heatmap. Only available when mode = 'lineages'.

  • show_absorption_probabilities (bool) – Whether to also plot absorption probabilities alongside the smoothed expression. Only available when mode = 'lineages'.

  • cluster_genes (bool) – Whether to cluster genes using seaborn.clustermap() when mode = 'lineages'.

  • keep_gene_order (bool) – Whether to keep the gene order for later lineages after the first was sorted. Only available when cluster_genes = False and mode = 'lineages'.

  • scale (bool) – Whether to normalize the gene expression [0, 1] range.

  • n_convolve (Optional[int]) – Size of the convolution window when smoothing absorption probabilities.

  • show_all_genes (bool) – Whether to show all genes on y-axis.

  • cbar (bool) – Whether to show the colorbar.

  • lineage_height (float) – Height of a bar when mode = 'genes'.

  • fontsize (Optional[float]) – Size of the title’s font.

  • xlabel (Optional[str]) – Label on the x-axis. If None, it is determined based on time_key.

  • cmap (ListedColormap) – Colormap to use when visualizing the smoothed expression.

  • dendrogram (bool) – Whether to show dendrogram when cluster_genes = True.

  • return_genes (bool) – Whether to return the sorted or clustered genes. Only available when mode = 'lineages'.

  • return_models (bool) – If True, return the fitted models for each gene in genes and lineage in lineages.

  • return_figure (bool) – Whether to return the figure object. Sets return_genes = True

  • show_progress_bar (bool) – Whether to show a progress bar. Disabling it may slightly improve performance.

  • n_jobs (Optional[int]) – Number of parallel jobs. If -1, use all available cores. If None or 1, the execution is sequential.

  • backend (Literal[‘loky’, ‘multiprocessing’, ‘threading’]) – Which backend to use for parallelization. See joblib.Parallel for valid options.

  • figsize (Optional[Tuple[float, float]]) – Size of the figure.

  • dpi (Optional[int]) – Dots per inch.

  • save (Union[str, Path, None]) – Filename where to save the plot.

  • kwargs (Any) – Keyword arguments for cellrank.models.BaseModel.prepare().

Return type:

Union[Dict[str, DataFrame], Tuple[Mapping[str, Mapping[str, BaseModel]], Dict[str, DataFrame]], None]



If return_models = False, just plots the figure and optionally saves it based on save.

Dict[str, Dict[str, cellrank.models.BaseModel]]

Otherwise returns the fitted models as {'gene_1': {'lineage_1': <model_11>, ...}, ...}. Models which have failed will be instances of cellrank.models.FailedModel.

If return_genes = True and mode = 'lineages', returns pandas.DataFrame containing the clustered or sorted genes.

If return_figure = True, returns a tuple containing the figure and genes.