ocelli.pl.projections

Contents

ocelli.pl.projections#

ocelli.pl.projections(adata, x: str, s: float = 1.0, c: str | None = None, phis: list = [10, 55, 100, 145, 190, 235, 280, 225], thetas: list = [10, 55, 100, 145], cdict: dict | None = None, cmap=None, vmin: float | None = None, vmax: float | None = None, figsize: tuple | None = None, fontsize: float = 6.0, title: str | None = None, showlegend: bool = True, markerscale: float = 1.0, random_state=None, save: str | None = None, dpi: int = 300)#

Project and visualize 3D data from multiple angles

This function creates 2D projections of 3D data stored in adata.obsm by projecting it onto planes defined by polar coordinates (phi, theta) using ocelli.tl.projection. The resulting 2D plots are organized in a grid based on the specified angles.

Parameters:
  • adata (anndata.AnnData) – The annotated data matrix.

  • x (str) – Key in adata.obsm containing the 3D data to project.

  • s (float) – Size of the scatter plot markers. (default: 1.0)

  • c (str or None) – Key in adata.obs specifying the color scheme. (default: None)

  • phis (list) – List of azimuthal angles (phi) in degrees, ranging from 0 to 360. (default: [10, 55, 100, 145, 190, 235, 280, 225])

  • thetas (list) – List of polar angles (theta) in degrees, ranging from 0 to 180. (default: [10, 55, 100, 145])

  • cdict (dict or None) – Dictionary mapping discrete color groups to colors. (default: None)

  • cmap (str or None) – Colormap for continuous color schemes. (default: None)

  • vmin (float or None) – Lower bound for continuous color schemes. (default: None)

  • vmax (float or None) – Upper bound for continuous color schemes. (default: None)

  • figsize (tuple or None) – Size of the figure. (default: None)

  • fontsize (float) – Font size for titles and labels. (default: 6.0)

  • title (str or None) – Title for the subplots. If None, defaults to ‘phi=…, theta=…’. (default: None)

  • showlegend (bool) – Whether to display a legend for discrete color schemes. (default: True)

  • markerscale (float) – Scale for the legend markers. (default: 1.0)

  • random_state (int or None) – Seed for reproducibility of random projections. (default: None)

  • save (str or None) – Path to save the figure 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 as oci
from anndata import AnnData
import numpy as np

# Example data
adata = AnnData(X=np.random.rand(100, 50))
adata.obsm["3D_data"] = np.random.rand(100, 3)
adata.obs["group"] = np.random.choice(["A", "B", "C"], 100)

# Generate projections
oci.pl.projections(
    adata,
    x="3D_data",
    c="group",
    phis=[0, 90, 180],
    thetas=[30, 60],
    figsize=(12, 8),
    s=3
)