biotapy.pl.richness

Contents

biotapy.pl.richness#

biotapy.pl.richness(adata, metric, *, x=None, color=None, ax=None)#

One point per sample for a stored alpha diversity metric.

Parameters:
  • adata (AnnData) – Samples x features with obs['alpha_<metric>'], written by biotapy.tl.alpha() with inplace=True.

  • metric (str) – The metric to plot, such as "shannon".

  • x (str | None (default: None)) – An obs column whose values place the points. By default one position per sample.

  • color (str | None (default: None)) – An obs column that colours the points, with a legend.

  • ax (Axes | None (default: None)) – Axes to draw on; by default a new figure’s.

Return type:

Axes

Returns:

matplotlib.axes.Axes The points, one per sample with a finite value.

Raises:
  • KeyError – obs['alpha_<metric>'] is missing (the message names the call that writes it), or x or color is not an obs column.

  • TypeError – x or color is a numeric column.

Notes

R equivalent: phyloseq::plot_richness Guide: Plotting

phyloseq computes estimate_richness and draws every measure in its own facet; biotapy reads what biotapy.tl.alpha() stored and draws one metric per axes. Samples with a NaN value, such as Shannon of an all-zero sample, are left out, as geom_point(na.rm = TRUE) does; a color group left with no point gets no legend entry. There are no standard-error bars: tl.alpha stores none.

obs['alpha_*'] columns survive feature changes (biotapy.pp.filter_features(), biotapy.pp.rarefy(), biotapy.pp.tax_glom()), but they still describe the old table: recompute with bt.tl.alpha(adata, metrics=[metric], inplace=True) before plotting.

Examples

>>> import biotapy as bt
>>> tdata = bt.datasets.toy()
>>> bt.tl.alpha(tdata, metrics=["shannon"], inplace=True)
>>> ax = bt.pl.richness(tdata, "shannon", x="group")
>>> ax.collections[0].get_offsets().shape
(6, 2)