nirs4all.visualization.chart_utils.annotator module
ChartAnnotator - Helper for adding annotations to charts.
- class nirs4all.visualization.chart_utils.annotator.ChartAnnotator(config: ChartConfig | Dict[str, Any] | None = None)[source]
Bases:
objectHelper for adding annotations to charts.
Centralizes text formatting, positioning, and color selection for chart annotations. Uses ChartConfig for styling.
- config
ChartConfig instance for customization.
- add_heatmap_annotations(ax, matrix: ndarray, normalized_matrix: ndarray, count_matrix: ndarray, x_labels: List, y_labels: List, show_counts: bool = True, precision: int = 3) None[source]
Add text annotations to heatmap cells.
- Parameters:
ax – Matplotlib axes object.
matrix – Original score matrix.
normalized_matrix – Normalized matrix for color selection.
count_matrix – Matrix of sample counts.
x_labels – List of x-axis labels.
y_labels – List of y-axis labels.
show_counts – Whether to show sample counts.
precision – Number of decimal places for scores.
- add_statistics_box(ax, values: List[float], position: str = 'upper right', precision: int = 4) None[source]
Add statistics text box to plot.
- Parameters:
ax – Matplotlib axes object.
values – List of values to compute statistics from.
position – Position string for text box placement.
precision – Number of decimal places.
- static get_text_color(background_value: float, threshold: float = 0.5) str[source]
Determine text color based on background for optimal contrast.
- Parameters:
background_value – Normalized background value (0-1).
threshold – Threshold for switching from white to black text.
- Returns:
Color string (always ‘black’ for consistency).