alphapepttools.pl.scree_plot#
- alphapepttools.pl.scree_plot(adata, ax, n_pcs=20, dim_space='obs', color='blue', embeddings_name=None, method='pca', scatter_kwargs=None)#
Scree plot showing explained variance for each principal component.
Creates a scatter plot displaying the percentage of variance explained by each principal component. Useful for determining how many PCs capture most of the variation in the data and for deciding how many components to retain for analysis.
- Parameters:
adata (
AnnData|DataFrame) – AnnData object containing PCA results (must have run PCA first).ax (
Axes) – Matplotlib axes object to plot on.n_pcs (
int(default:20)) – Number of principal components to plot on the x-axis.dim_space (
str(default:'obs')) – PCA space to retrieve variance from: - “obs”: Sample space PCA (default) - variance explained across samples - “var”: Feature space PCA - variance explained across featurescolor (
str(default:'blue')) – Color for the scatter points.embeddings_name (
str|None(default:None)) – Custom embeddings name if non-default name was used in the PCA function. If None, uses default naming convention.method (
Literal['pca','bpca'] (default:'pca')) – The method used for dimensionality reduction. Options are “pca” or “bpca” with “pca” as the default. This is used to construct the default keys ifembeddings_nameis None.scatter_kwargs (
dict|None(default:None)) – Additional keyword arguments passed to matplotlib scatter (e.g., s, alpha).
- Return type:
Examples
Basic scree plot:
fig, ax = plt.subplots() Plots.scree_plot(adata=adata, ax=ax, n_pcs=50)
Scree plot with custom styling:
fig, ax = plt.subplots() Plots.scree_plot(adata=adata, ax=ax, n_pcs=30, color="red", scatter_kwargs={"s": 50, "alpha": 0.8})
Feature space scree plot:
# Show variance explained in feature space PCA fig, ax = plt.subplots() Plots.scree_plot(adata=adata, ax=ax, n_pcs=20, dim_space="var")
Notes
PCA must be run on the AnnData object before calling this function
Y-axis shows percentage of total variance explained by each PC
dim_space=”obs” shows variance for sample projections (most common)
dim_space=”var” shows variance for feature projections
This is a convenience wrapper around scatter() with automatic variance data extraction