Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions src/scanpy/plotting/_anndata.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,31 @@ def scatter( # noqa: PLR0913
-------
If `show==False` a :class:`~matplotlib.axes.Axes` or a list of it.

Examples
--------
Plot two `.obs` annotations against each other and colour by a third.

.. plot::
:context: close-figs

import scanpy as sc
adata = sc.datasets.pbmc68k_reduced()
sc.pl.scatter(adata, x="n_counts", y="n_genes", color="bulk_labels")

Plot expression of two genes against each other.

.. plot::
:context: close-figs

sc.pl.scatter(adata, x="CD79A", y="CD3D", color="bulk_labels")

Use a precomputed embedding via the `basis` argument.

.. plot::
:context: close-figs

sc.pl.scatter(adata, basis="umap", color="bulk_labels")

"""
# color can be a obs column name or a matplotlib color specification (or a collection thereof)
if color is not None:
Expand Down Expand Up @@ -618,6 +643,27 @@ def ranking( # noqa: PLR0912, PLR0913
-------
Returns matplotlib gridspec with access to the axes.

Examples
--------
Show the genes with the highest loading on the first three principal components.
PCA in :func:`~scanpy.datasets.pbmc68k_reduced` was computed on highly-variable
genes only, so we subset to those genes before ranking.

.. plot::
:context: close-figs

import scanpy as sc
adata = sc.datasets.pbmc68k_reduced()
adata_hv = adata[:, adata.var["highly_variable"]].copy()
sc.pl.ranking(adata_hv, attr="varm", keys="PCs", indices=[0, 1, 2])

Include the lowest-loading genes alongside the highest.

.. plot::
:context: close-figs

sc.pl.ranking(adata_hv, attr="varm", keys="PCs", indices=[0, 1, 2], include_lowest=True)

"""
if isinstance(keys, str) and indices is not None:
scores = getattr(adata, attr)[keys][:, indices]
Expand Down
12 changes: 12 additions & 0 deletions src/scanpy/plotting/_tools/paga.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,18 @@ def paga_compare( # noqa: PLR0912, PLR0913
-------
A list of :class:`~matplotlib.axes.Axes` if `show` is `False`.

Examples
--------
Compute a PAGA graph on the bundled PBMC dataset and show it next to the UMAP embedding.

.. plot::
:context: close-figs

import scanpy as sc
adata = sc.datasets.pbmc68k_reduced()
sc.tl.paga(adata, groups="bulk_labels")
sc.pl.paga_compare(adata, basis="umap")

"""
axs, _, _, _ = _utils.setup_axes(panels=[0, 1], right_margin=right_margin)
if color is None:
Expand Down
19 changes: 19 additions & 0 deletions src/scanpy/plotting/_tools/scatterplots.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,25 @@ def embedding( # noqa: PLR0912, PLR0913, PLR0915
-------
If `show==False` a :class:`~matplotlib.axes.Axes` or a list of it.

Examples
--------
Plot a precomputed UMAP embedding coloured by the `'bulk_labels'` cell-type annotation.

.. plot::
:context: close-figs

import scanpy as sc
adata = sc.datasets.pbmc68k_reduced()
sc.pl.embedding(adata, basis="umap", color="bulk_labels")

Show several panels in a single call by passing a list of keys to `color`,
mixing categorical annotations and gene expression.

.. plot::
:context: close-figs

sc.pl.embedding(adata, basis="umap", color=["bulk_labels", "CD3D", "LYZ"])

"""
#####################
# Argument handling #
Expand Down
Loading