liana.pl.elbow#
- liana.pl.elbow(adata=None, errors=None, rank=None, figure_size=(5, 4), return_fig=True)#
Plot the NMF reconstruction error per rank, with the estimated elbow.
- Parameters:
- adata
AnnData|None(default:None) AnnData on which
liana.ms.nmf()was run withn_components=None; readsadata.uns['nmf_errors']andadata.uns['nmf_rank'].- errors
DataFrame|None(default:None) Error curve as returned by
liana.ms.estimate_elbow(); takes precedence overadata.uns['nmf_errors'].- rank
int|None(default:None) Estimated rank to mark with a dashed line; takes precedence over
adata.uns['nmf_rank'].- figure_size
tuple[float,float] (default:(5, 4)) Figure x,y size
- return_fig
bool(default:True) boolwhether to return the fig object.
- adata
- Return type:
- Returns:
The resulting elbow plot.
- Raises:
ValueError – If no error curve is available, e.g.
nmfwas run with a fixedn_components.
Examples
>>> import liana as li >>> adata = li.ds.generate_toy_spatial() >>> lrdata = li.mt.bivariate(adata, resource_name="consensus", local_name="cosine", global_name=None, n_perms=None) >>> li.ms.nmf(lrdata, n_components=None, k_range=range(1, 6), random_state=0, max_iter=200) >>> p = li.pl.elbow(lrdata)