snapatac2.pl.spectral_eigenvalues#
- snapatac2.pl.spectral_eigenvalues(adata, width=600, height=400, show=True, interactive=True, out_file=None)[source]#
Plot spectral embedding eigenvalues and mark the elbow.
Use this function after spectral decomposition to choose the number of eigenvectors retained for downstream analysis.
Anti-Patterns#
Do NOT call this before computing spectral eigenvalues. The input must contain
adata.uns["spectral_eigenvalue"].Do NOT treat this as a pure plotting helper; it also writes the inferred elbow to
adata.uns["num_eigen"].
- param adata:
Annotated data matrix containing
uns["spectral_eigenvalue"].- type adata:
AnnData
- param width:
Width of the rendered plot in pixels.
- type width:
int
- param height:
Height of the rendered plot in pixels.
- type height:
int
- param show:
Whether to display the figure immediately.
- type show:
bool
- param interactive:
Whether to display an interactive Plotly figure when
show=True.- type interactive:
bool
- param out_file:
Output path for saving the plot. Supported suffixes include
.svg,.pdf,.png, and.html.- type out_file:
str | None
- returns:
Returns a Plotly figure when
show=Falseandout_file=None; otherwise renders or saves the plot and returnsNone.- rtype:
plotly.graph_objects.Figure’ | None
Examples
>>> import numpy as np >>> import snapatac2 as snap >>> adata = snap.AnnData(X=np.ones((3, 3))) >>> adata.uns["spectral_eigenvalue"] = np.array([4.0, 2.5, 1.2, 0.4]) >>> fig = snap.pl.spectral_eigenvalues(adata, show=False) >>> fig.update_layout(title="Spectral eigenvalues")