ocelli.pl.scatter#
- ocelli.pl.scatter(adata: AnnData, x: str, s: float = 1.0, c: str | None = None, cdict: dict | None = None, cmap=None, vmin=None, vmax=None, xlim: tuple | None = None, ylim: tuple | None = None, figsize=None, ncols: int = 4, fontsize: int = 6, title: str | None = None, showlegend: bool = True, markerscale: float = 1.0, save: str | None = None, dpi: int = 300)#
2D scatter plots
This function creates a 2D scatter plot based on data stored in adata.obsm and optionally colors the points using a single (adata.obs) or multiple (adata.obsm) color schemes. For multiple color schemes, a grid of plots is generated.
- Parameters:
adata (anndata.AnnData) – The annotated data matrix.
x (str) – Key in adata.obsm containing the 2D data for plotting.
s (float) – Size of the scatter plot markers. (default: 1.0)
c (str or None) – Key in adata.obs or adata.obsm specifying the color scheme. (default: None)
cdict (dict or None) – A dictionary mapping discrete groups in the color scheme to specific colors. Used for discrete color schemes. (default: None)
cmap (str or None) – Colormap for continuous color schemes. Can be a string name of a Matplotlib colormap or a custom colormap. (default: None)
vmin (float or None) – Lower bound of the colormap for continuous color schemes. (default: None)
vmax (float or None) – Upper bound of the colormap for continuous color schemes. (default: None)
xlim (tuple or None) – Tuple defining the x-axis limits. (default: None)
ylim (tuple or None) – Tuple defining the y-axis limits. (default: None)
figsize (tuple or None) – Tuple specifying the figure size. (default: None)
ncols (int) – Number of columns in the grid when plotting multiple color schemes from adata.obsm. (default: 4)
fontsize (int) – Font size for plot labels and titles. (default: 6)
title (str or None) – Title of the plot. If multiple plots are generated, this applies to each subplot. (default: None)
showlegend (bool) – Whether to display a legend for discrete color schemes. (default: True)
markerscale (float) – Scale of the legend markers. (default: 1.0)
save (str or None) – Path to save the plot as a file. If None, the plot is returned as a Matplotlib figure. (default: None)
dpi (int) – Resolution of the saved figure in dots per inch (DPI). (default: 300)
- Returns:
If save is 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 as oci from anndata import AnnData import numpy as np # Example data adata = AnnData(X=np.random.rand(100, 50)) adata.obsm["embedding"] = np.random.rand(100, 2) adata.obs["group"] = np.random.choice(["A", "B", "C"], 100) # Generate scatter plot oci.pl.scatter(adata, x="embedding", c="group", s=5, title="Scatter Plot Example")