liana.plotting.target_metrics

Contents

liana.plotting.target_metrics#

liana.plotting.target_metrics(misty=None, stat=None, target_metrics=None, top_n=None, ascending=False, key=None, filter_fun=None, figure_size=(5, 5), aggregate_fun=None, return_fig=True)#

Plot target metrics.

Parameters:
  • misty (MistyData (default: None)) – MistyData object with modelling results

  • stat (str (default: None)) – Statistic to plot

  • target_metrics (DataFrame (default: None)) – A target_metrics DataFrame

  • top_n (int (default: None)) – top_n entities to plot.

  • ascending (bool (default: False)) – Whether to sort in ascending order

  • key (Callable (default: None)) – Function to use to sort the dataframe

  • filter_fun (Callable (default: None)) – A function, applied along the columns (axis=1), used to filter the results to be plotted.

  • aggregate_fun (Callable (default: None)) – A function used to aggregate the results to be plotted.

  • figure_size (tuple[float, float] (default: (5, 5))) – Figure x,y size

  • return_fig (bool (default: True)) – bool whether to return the fig object.

Return type:

Figure

Returns:

Returns a plotnine plot.

Raises:

ValueError – If the misty input or stat provided are not valid.

Examples

Fit a MiSTy model, then plot one bar per target. stat chooses which of the misty.uns['target_metrics'] columns is shown, and orders the targets by it:

>>> import liana as li
>>> adata = li.testing.generate_toy_spatial()
>>> adata = adata[:, adata.var_names[:5]].copy()
>>> misty = li.mt.genericMistyData(intra=adata, bandwidth=200,
...                                set_diag=True)
>>> misty(model=li.mt.sp.LinearModel)
>>> p = li.pl.target_metrics(misty, stat='gain_R2')

Pass aggregate_fun (e.g. numpy.mean) to summarise a masked model’s per-group rows into boxplots.