snapatac2.pl.umap#

snapatac2.pl.umap(adata, color=None, use_rep='X_umap', marker_size=None, marker_opacity=1, sample_size=None, **kwargs)[source]#

Plot a two- or three-dimensional UMAP embedding.

Use this function to visualize cells from adata.obsm[use_rep] or from a numeric embedding array.

Anti-Patterns#

  • Do NOT pass color as a column name when adata is a raw NumPy array; provide an array of color values instead.

  • Do NOT use sample_size when every point must be displayed. Sampling is random and only affects the plotted points.

param adata:

Annotated data matrix containing obsm[use_rep], or an embedding array with cells as rows and coordinates as columns.

type adata:

AnnData | np.ndarray

param color:

Observation column name to color by when adata is AnnData, or a vector of color values aligned to the embedding rows.

type color:

str | np.ndarray | None

param use_rep:

Key in adata.obsm containing the UMAP coordinates.

type use_rep:

str

param marker_size:

Marker size. If None, choose a size from the number of plotted cells.

type marker_size:

float

param marker_opacity:

Marker opacity between 0 and 1.

type marker_opacity:

float

param sample_size:

Maximum number of cells to plot. If the embedding has more rows, randomly sample this many rows without replacement.

type sample_size:

int | None

type **kwargs:

param **kwargs:

Additional rendering options passed to snapatac2.pl.render_plot, such as show, interactive, out_file, and scale.

returns:

Returns a Plotly figure when show=False and out_file=None; otherwise renders or saves the plot and returns None.

rtype:

plotly.graph_objects.Figure’ | None

Examples

>>> import numpy as np
>>> import snapatac2 as snap
>>> embedding = np.array([[0.0, 0.1], [1.0, 1.1], [2.0, 0.9]])
>>> labels = np.array(["A", "B", "A"])
>>> fig = snap.pl.umap(embedding, color=labels, show=False)
>>> fig.update_layout(title="UMAP")