ocelli.pl.bar#
- ocelli.pl.bar(adata: AnnData, groups: str, values: str, height: str = 'median', cdict=None, figsize=None, fontsize: int = 6, showlegend: bool = True, markerscale: float = 1.0, save: str | None = None, dpi: int = 300)#
Feature bar plots
Generates bar plots showing the mean or median values of features from adata.obs or adata.obsm. Separate bar plots are created for each group or cluster defined in adata.obs[groups].
- Parameters:
adata (anndata.AnnData) – The annotated data matrix.
groups (str) – Key in adata.obs specifying the groups or clusters for which bar plots are generated.
values (str) – Key in adata.obs or adata.obsm specifying the values to be plotted.
height (str) – The metric used for bar heights. Valid options: median, mean. (default: median)
cdict (dict or None) – A dictionary mapping groups to colors. If None, colors are generated automatically. (default: None)
figsize (tuple or None) – Size of the plot figure. (default: None)
fontsize (int) – Font size for plot labels and legends. (default: 6)
showlegend (bool) – Whether to display a legend for the groups. (default: True)
markerscale (float) – Scale of the legend markers. (default: 1.0)
save (str or None) – Path to save the plot as an image. If None, the plot is returned as a Matplotlib figure. (default: None)
dpi (int) – Resolution of the saved figure in dots per inch (DPI). Controls the image quality. (default: 300)
- Returns:
If save=None: Returns a Matplotlib figure object.
Otherwise, saves the plot to the specified path and does not return anything.
- Return type:
matplotlib.figure.Figure or None
- Example:
import ocelli.pl as pl from anndata import AnnData import numpy as np import pandas as pd # Example data adata = AnnData(X=np.random.rand(100, 50)) adata.obs["groups"] = np.random.choice(["A", "B", "C"], 100) adata.obs["values"] = np.random.rand(100) # Generate bar plot pl.bar(adata, groups="groups", values="values", height="mean", fontsize=10, showlegend=True)