napistu_torch.visualization.advanced_metrics
Advanced metrics like summaries of relation-type-specific AUCs.
Functions
|
Plot multiple value variables side-by-side with horizontal bars. |
|
Create a grouped barplot with flexible column mapping. |
- napistu_torch.visualization.advanced_metrics.plot_combined_grouped_barplot(df: DataFrame, figsize: Tuple[int, int] = (16, 10), category: str = 'relation_type', attribute: str = 'experiment', value: str = 'val_auc', value_vars: List[str] = ['val_auc', 'test_auc'], category_order: List[str] | None = None, attribute_order: List[str] | None = None, category_label: str | None = None, attribute_label: str | None = None, value_label: str = 'AUC', titles: List[str] | None = None, palette: str | List[str] | None = 'Set2', value_lim: Tuple[float, float] | None = None, legend_loc: str = 'lower left') Tuple[Figure, List[Axes]]
Plot multiple value variables side-by-side with horizontal bars.
- valuestr
Column name for values (x-axis for horizontal)
- value_varsList[str]
Column names for values (x-axis for horizontal)
- category_orderOptional[List[str]]
Custom order for categories
- attribute_orderOptional[List[str]]
Custom order for attributes (hue)
- category_labelOptional[str]
Label for category axis (defaults to category column name)
- attribute_labelOptional[str]
Label for legend (defaults to attribute column name)
- value_labelstr
Label for value axis
- titlesOptional[List[str]]
Plot titles for each value variable
- palettestr
Color palette to use. Can be a string (e.g., “Set2”) or a list of colors.
- value_limOptional[Tuple[float, float]]
Limits for value axis (e.g., (0.7, 1.0))
- legend_locstr
Legend location
- Returns:
Figure and axes tuple (ax1 for validation AUC, ax2 for test AUC)
- Return type:
Tuple[plt.Figure, Tuple[plt.Axes, plt.Axes]]
Examples
>>> df = pd.DataFrame({ >>> 'relation_type': ['protein_protein', 'protein_metabolite', 'metabolite_metabolite'], >>> 'experiment': ['experiment1', 'experiment1', 'experiment1'], >>> 'val_auc': [0.8, 0.7, 0.9], >>> 'test_auc': [0.75, 0.65, 0.85] >>> }) >>> plot_combined_grouped_barplot(df, category='relation_type', attribute='experiment', value='val_auc')
- napistu_torch.visualization.advanced_metrics.plot_grouped_barplot(df: DataFrame, category: str, value: str, attribute: str, ax: Axes | None = None, figsize: Tuple[int, int] = (8, 10), orientation: str = 'horizontal', value_label: str = 'Value', category_label: str | None = None, attribute_label: str | None = None, title: str | None = None, palette: str | List[str] | None = 'Set2', value_lim: Tuple[float, float] | None = None, legend_loc: str = 'lower right', category_order: List[str] | None = None, attribute_order: List[str] | None = None) Tuple[Figure, Axes]
Create a grouped barplot with flexible column mapping.
- Parameters:
df (pd.DataFrame) – Input dataframe
category (str) – Column name for categories (y-axis for horizontal)
value (str) – Column name for values (x-axis for horizontal)
attribute (str) – Column name for grouping/hue
ax (matplotlib axis, optional) – Axis to plot on. If None, creates new figure
figsize (tuple) – Figure size if creating new figure
orientation (str) – ‘horizontal’ or ‘vertical’
value_label (str) – Label for value axis
category_label (str, optional) – Label for category axis (defaults to category column name)
attribute_label (str, optional) – Label for legend (defaults to attribute column name)
title (str, optional) – Plot title
palette (Union[str, List[str]]) – Color palette to use. Can be a string (e.g., “Set2”) or a list of colors.
value_lim (tuple, optional) – Limits for value axis (e.g., (0.7, 1.0))
legend_loc (str) – Legend location
category_order (list, optional) – Custom order for categories
attribute_order (list, optional) – Custom order for attributes (hue)
- Returns:
Figure and axis objects
- Return type:
Tuple[plt.Figure, plt.Axes]
Examples
>>> df = pd.DataFrame({ >>> 'relation_type': ['protein_protein', 'protein_metabolite', 'metabolite_metabolite'], >>> 'experiment': ['experiment1', 'experiment1', 'experiment1'], >>> 'val_auc': [0.8, 0.7, 0.9], >>> 'test_auc': [0.75, 0.65, 0.85] >>> }) >>> plot_grouped_bars(df, 'relation_type', 'val_auc', 'experiment', orientation='horizontal')