.box
- proteopy.pl.box(adata, keys, group_by=None, order=None, layer=None, zero_to_na=False, fill_na=None, log_transform=None, color_scheme=None, figsize=(8.0, 5.0), title=None, xlabel_rotation=0, ylabel=None, show_points=False, point_size=3, point_alpha=0.7, show=True, save=None, ax=False)[source]
Boxplot of intensities for one or more variables.
- Parameters:
adata (AnnData) –
AnnDatawith intensity data in.Xor a specified layer.keys (str | list[str]) – Variable name(s) present in
adata.var_namesto plot.group_by (str | None, optional) – Column in
adata.obswhose unique values define the x-axis categories. WhenNone, all observations are pooled into a single box.order (list[str] | None, optional) – Subset and order groups when
group_byis set. Only groups listed inorderare shown, in the given sequence. Ignored whengroup_byisNone.layer (str | None, optional) – Key in
adata.layersproviding the intensity matrix. WhenNone, usesadata.X.zero_to_na (bool, optional) – Convert zero intensities to
NaNbefore other transforms.fill_na (float | int | None, optional) – Replace missing intensities with this value before transformations.
log_transform (float | None, optional) – Base for log transformation. When set, applies
log(value + 1, base).color_scheme (str | dict | list | None, optional) – Color mapping for groups. Accepts a named Matplotlib colormap, a dict mapping group names to colors, or a list of colors.
figsize (tuple[float, float], optional) – Figure dimensions (width, height) in inches.
title (str | None, optional) – Plot title. When
None, defaults to the variable name.xlabel_rotation (float, optional) – Rotation angle (degrees) for x-axis tick labels.
ylabel (str | None, optional) – Label for the y-axis.
show_points (bool, optional) – Overlay individual observations as a strip plot on top of each box.
point_size (float, optional) – Marker size for the individual points when
show_pointsisTrue.point_alpha (float, optional) – Opacity for individual points when
show_pointsisTrue.show (bool, optional) – Call
matplotlib.pyplot.show()to display the plot.save (str | os.PathLike | None, optional) – File path to save the figure. For a single key, the format is inferred from the file extension (e.g.
.png,.pdf,.svg). For multiple keys, saved as a multi-page PDF.ax (bool, optional) – If
True, return the underlying Axes object(s) instead ofNone.
- Returns:
The Matplotlib Axes object(s) if
ax=True, otherwiseNone.- Return type:
Axes | list[Axes] | None
- Raises:
KeyError – If any element of
keysis not inadata.var_names, ifgroup_byis not inadata.obs, or iflayeris not inadata.layers.ValueError – If
keysis empty, ifordercontains values not present in thegroup_bycolumn, iflog_transformis not positive or equals 1, or ifgroup_byisNoneandorderis provided.
Examples
Single variable, grouped by condition:
>>> import proteopy as pr >>> pr.pl.box(adata, keys="ProteinA", group_by="condition")
Multiple variables saved to PDF:
>>> pr.pl.box( ... adata, ... keys=["ProteinA", "ProteinB"], ... group_by="condition", ... save="boxplots.pdf", ... )