decoupler.pl.dotplot

Contents

decoupler.pl.dotplot#

decoupler.pl.dotplot(df, x, y, c, s, top=10, scale=0.15, cmap='RdBu_r', vcenter=None, kw_scatter=None, **kwargs)#

Plot results of enrichment analysis as dots.

Parameters:
  • df (DataFrame) – DataFrame containing enrichment results.

  • x (str) – Name of the column containing values to place on the x-axis.

  • y (str) – Name of the column containing values to place on the y-axis.

  • c (str) – Name of the column containing values to use for coloring.

  • s (str) – Name of the column containing values to use for setting the size of the dots.

  • top (int | float (default: 10)) – Number of top sources to plot.

  • scale (int | float (default: 0.15)) – Scale of the dots.

  • cmap (str (default: 'RdBu_r')) – Colormap to use.

  • vcenter (int | float | None (default: None)) – The value representing the center of the color scale.

  • kw_scatter (dict | None (default: None)) – Keyword arguments passed to matplotlib.pyplot.scatter.

  • ax – An existing matplotlib.axes._axes.Axes instance to plot on. If None, a new figure and axes will be created.

  • figsize – Size of the figure in inches as (width, height).

  • dpi – Dots per inch for the figure resolution.

  • return_fig – If True, plotting methods should return the figure object instead of showing it.

  • save – If set, path to save the plot automatically to a file.

Return type:

None | Figure

Returns:

If return_fig=True, returns matplotlib.figure.Figure instance.

Example

import decoupler as dc
import scanpy as sc
import numpy as np

adata, net = dc.ds.toy()
sc.tl.rank_genes_groups(adata, groupby="group")
deg = sc.get.rank_genes_groups_df(adata, group=None)
mat = deg.pivot(index="group", columns="names", values="scores")
scores, padjs = dc.mt.ulm(mat, net, tmin=3)
df = (
    scores.loc[["A"]]
    .melt(value_name="score")
    .merge(
        padjs.loc[["A"]]
        .melt(value_name="padj")
        .assign(padj=lambda x: x["padj"].clip(2.22e-16, 1))
        .assign(padj=lambda x: -np.log10(x["padj"]))
    )
)
dc.pl.dotplot(df=df, x="score", y="variable", s="padj", c="score", scale=1, top=3)