Skip to content

Commit 6af627e

Browse files
authored
docs(plotting): add inline example plots for 4 sc.pl functions (#1664) (#4103)
1 parent 1a3141b commit 6af627e

3 files changed

Lines changed: 77 additions & 0 deletions

File tree

src/scanpy/plotting/_anndata.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,31 @@ def scatter( # noqa: PLR0913
157157
-------
158158
If `show==False` a :class:`~matplotlib.axes.Axes` or a list of it.
159159
160+
Examples
161+
--------
162+
Plot two `.obs` annotations against each other and colour by a third.
163+
164+
.. plot::
165+
:context: close-figs
166+
167+
import scanpy as sc
168+
adata = sc.datasets.pbmc68k_reduced()
169+
sc.pl.scatter(adata, x="n_counts", y="n_genes", color="bulk_labels")
170+
171+
Plot expression of two genes against each other.
172+
173+
.. plot::
174+
:context: close-figs
175+
176+
sc.pl.scatter(adata, x="CD79A", y="CD3D", color="bulk_labels")
177+
178+
Use a precomputed embedding via the `basis` argument.
179+
180+
.. plot::
181+
:context: close-figs
182+
183+
sc.pl.scatter(adata, basis="umap", color="bulk_labels")
184+
160185
"""
161186
# color can be a obs column name or a matplotlib color specification (or a collection thereof)
162187
if color is not None:
@@ -587,6 +612,27 @@ def ranking( # noqa: PLR0912, PLR0913
587612
-------
588613
Returns matplotlib gridspec with access to the axes.
589614
615+
Examples
616+
--------
617+
Show the genes with the highest loading on the first three principal components.
618+
PCA in :func:`~scanpy.datasets.pbmc68k_reduced` was computed on highly-variable
619+
genes only, so we subset to those genes before ranking.
620+
621+
.. plot::
622+
:context: close-figs
623+
624+
import scanpy as sc
625+
adata = sc.datasets.pbmc68k_reduced()
626+
adata_hv = adata[:, adata.var["highly_variable"]].copy()
627+
sc.pl.ranking(adata_hv, attr="varm", keys="PCs", indices=[0, 1, 2])
628+
629+
Include the lowest-loading genes alongside the highest.
630+
631+
.. plot::
632+
:context: close-figs
633+
634+
sc.pl.ranking(adata_hv, attr="varm", keys="PCs", indices=[0, 1, 2], include_lowest=True)
635+
590636
"""
591637
if isinstance(keys, str) and indices is not None:
592638
scores = getattr(adata, attr)[keys][:, indices]

src/scanpy/plotting/_tools/paga.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,18 @@ def paga_compare( # noqa: PLR0912, PLR0913
9797
-------
9898
A list of :class:`~matplotlib.axes.Axes` if `show` is `False`.
9999
100+
Examples
101+
--------
102+
Compute a PAGA graph on the bundled PBMC dataset and show it next to the UMAP embedding.
103+
104+
.. plot::
105+
:context: close-figs
106+
107+
import scanpy as sc
108+
adata = sc.datasets.pbmc68k_reduced()
109+
sc.tl.paga(adata, groups="bulk_labels")
110+
sc.pl.paga_compare(adata, basis="umap")
111+
100112
"""
101113
axs, _, _, _ = _utils.setup_axes(panels=[0, 1], right_margin=right_margin)
102114
if color is None:

src/scanpy/plotting/_tools/scatterplots.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,25 @@ def embedding( # noqa: PLR0912, PLR0913, PLR0915
120120
-------
121121
If `show==False` a :class:`~matplotlib.axes.Axes` or a list of it.
122122
123+
Examples
124+
--------
125+
Plot a precomputed UMAP embedding coloured by the `'bulk_labels'` cell-type annotation.
126+
127+
.. plot::
128+
:context: close-figs
129+
130+
import scanpy as sc
131+
adata = sc.datasets.pbmc68k_reduced()
132+
sc.pl.embedding(adata, basis="umap", color="bulk_labels")
133+
134+
Show several panels in a single call by passing a list of keys to `color`,
135+
mixing categorical annotations and gene expression.
136+
137+
.. plot::
138+
:context: close-figs
139+
140+
sc.pl.embedding(adata, basis="umap", color=["bulk_labels", "CD3D", "LYZ"])
141+
123142
"""
124143
#####################
125144
# Argument handling #

0 commit comments

Comments
 (0)