.hclustv_elbow
- proteopy.pl.hclustv_elbow(adata, linkage_key='auto', values_key='auto', k=15, figsize=(6.0, 4.0), show=True, ax=False, save=None, verbose=True)[source]
Plot within-cluster sum of squares (elbow plot) for hierarchical clustering.
Evaluates clustering by computing WCSS for cluster counts ranging from 1 to
k. The “elbow” point where WCSS reduction diminishes suggests an optimal cluster count.- Parameters:
adata (AnnData) –
AnnDatawith clustering results fromproteopy.tl.hclustv_tree()stored in.uns.linkage_key (str) – Key in
adata.unsfor the linkage matrix. When'auto', auto-detects keys matchinghclustv_linkage;*.values_key (str) – Key in
adata.unsfor the profile values DataFrame. When'auto', auto-detects keys matchinghclustv_values;*.k (int) – Maximum number of clusters to evaluate. WCSS is computed for cluster counts from 1 to
k(inclusive).figsize (tuple[float, float]) – Matplotlib figure size in inches.
show (bool) – Display the figure.
ax (bool) – Return the Matplotlib Axes object instead of displaying.
save (str | Path | None) – File path for saving the figure.
verbose (bool) – Print status messages including auto-detected keys.
- Returns:
Axes object when
axisTrue; otherwiseNone.- Return type:
Axes | None
- Raises:
ValueError – If no clustering results are found in
adata.uns, if multiple candidates exist and keys are not specified, or ifk < 1.KeyError – If the specified
linkage_keyorvalues_keyis not found.
Examples
>>> import proteopy as pr >>> adata = pr.datasets.example_peptide_data() >>> pr.tl.hclustv_tree(adata, group_by="condition") >>> pr.pl.hclustv_elbow(adata, k=10)