Skip to content

Commit dfa54db

Browse files
Backport PR #4103 on branch 1.12.x (docs(plotting): add inline example plots for 4 sc.pl functions (#1664)) (#4111)
Co-authored-by: Olajumoke Akinremi <106763970+Hore01@users.noreply.github.com>
1 parent 664276d commit dfa54db

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
@@ -176,6 +176,31 @@ def scatter( # noqa: PLR0913
176176
-------
177177
If `show==False` a :class:`~matplotlib.axes.Axes` or a list of it.
178178
179+
Examples
180+
--------
181+
Plot two `.obs` annotations against each other and colour by a third.
182+
183+
.. plot::
184+
:context: close-figs
185+
186+
import scanpy as sc
187+
adata = sc.datasets.pbmc68k_reduced()
188+
sc.pl.scatter(adata, x="n_counts", y="n_genes", color="bulk_labels")
189+
190+
Plot expression of two genes against each other.
191+
192+
.. plot::
193+
:context: close-figs
194+
195+
sc.pl.scatter(adata, x="CD79A", y="CD3D", color="bulk_labels")
196+
197+
Use a precomputed embedding via the `basis` argument.
198+
199+
.. plot::
200+
:context: close-figs
201+
202+
sc.pl.scatter(adata, basis="umap", color="bulk_labels")
203+
179204
"""
180205
# color can be a obs column name or a matplotlib color specification (or a collection thereof)
181206
if color is not None:
@@ -618,6 +643,27 @@ def ranking( # noqa: PLR0912, PLR0913
618643
-------
619644
Returns matplotlib gridspec with access to the axes.
620645
646+
Examples
647+
--------
648+
Show the genes with the highest loading on the first three principal components.
649+
PCA in :func:`~scanpy.datasets.pbmc68k_reduced` was computed on highly-variable
650+
genes only, so we subset to those genes before ranking.
651+
652+
.. plot::
653+
:context: close-figs
654+
655+
import scanpy as sc
656+
adata = sc.datasets.pbmc68k_reduced()
657+
adata_hv = adata[:, adata.var["highly_variable"]].copy()
658+
sc.pl.ranking(adata_hv, attr="varm", keys="PCs", indices=[0, 1, 2])
659+
660+
Include the lowest-loading genes alongside the highest.
661+
662+
.. plot::
663+
:context: close-figs
664+
665+
sc.pl.ranking(adata_hv, attr="varm", keys="PCs", indices=[0, 1, 2], include_lowest=True)
666+
621667
"""
622668
if isinstance(keys, str) and indices is not None:
623669
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
@@ -113,6 +113,18 @@ def paga_compare( # noqa: PLR0912, PLR0913
113113
-------
114114
A list of :class:`~matplotlib.axes.Axes` if `show` is `False`.
115115
116+
Examples
117+
--------
118+
Compute a PAGA graph on the bundled PBMC dataset and show it next to the UMAP embedding.
119+
120+
.. plot::
121+
:context: close-figs
122+
123+
import scanpy as sc
124+
adata = sc.datasets.pbmc68k_reduced()
125+
sc.tl.paga(adata, groups="bulk_labels")
126+
sc.pl.paga_compare(adata, basis="umap")
127+
116128
"""
117129
axs, _, _, _ = _utils.setup_axes(panels=[0, 1], right_margin=right_margin)
118130
if color is None:

src/scanpy/plotting/_tools/scatterplots.py

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

0 commit comments

Comments
 (0)