Skip to content

API: Plotting

Optional helpers that require the plots extra (pip install "fiducio[plots]"). Matplotlib is imported lazily.

reliability_diagram

reliability_diagram(probs: Any, targets: Any, mask: Any | None = None, ignore_index: int = -100, n_bins: int = 15, *, ax: Any | None = None, title: str | None = 'Reliability diagram', metric: str | None = 'ece', class_index: int | None = None) -> Any

Draw top-1 or class reliability and return the matplotlib Axes.

Parameters:

Name Type Description Default
probs Any

(B, C, *spatial) probabilities.

required
targets Any

(B, *spatial) integer labels or (B, C, *spatial) floating class distributions, including mean human responses.

required
mask Any | None

Optional voxel selection (see :class:fiducio.Calibrator).

None
ignore_index Any | None

Optional voxel selection (see :class:fiducio.Calibrator).

None
n_bins int

Number of confidence bins.

15
ax Any | None

Existing axes to draw on. A new figure/axes is created when None.

None
title str | None

Plot title (None to omit).

'Reliability diagram'
metric str | None

Which calibration error to annotate the panel with: "ece" (population-weighted, the default), "ace" (unweighted mean over non-empty bins — see :func:fiducio.unweighted_calibration_error), or None to omit the annotation.

'ece'
class_index int | None

Optional class whose probability is compared with the observed class proportion (MHR for soft targets). The annotated ECE is against these targets, not the mean ECE against individual raters. See TwinTrack, Kirscher et al., MIDL 2026, https://arxiv.org/abs/2604.15950v2.

None

Returns:

Type Description
Axes

The axes the diagram was drawn on.

Source code in src/fiducio/plots/__init__.py
def reliability_diagram(
    probs: Any,
    targets: Any,
    mask: Any | None = None,
    ignore_index: int = -100,
    n_bins: int = 15,
    *,
    ax: Any | None = None,
    title: str | None = "Reliability diagram",
    metric: str | None = "ece",
    class_index: int | None = None,
) -> Any:
    """Draw top-1 or class reliability and return the matplotlib ``Axes``.

    Parameters
    ----------
    probs:
        ``(B, C, *spatial)`` probabilities.
    targets:
        ``(B, *spatial)`` integer labels or ``(B, C, *spatial)`` floating class
        distributions, including mean human responses.
    mask, ignore_index:
        Optional voxel selection (see :class:`fiducio.Calibrator`).
    n_bins:
        Number of confidence bins.
    ax:
        Existing axes to draw on. A new figure/axes is created when ``None``.
    title:
        Plot title (``None`` to omit).
    metric:
        Which calibration error to annotate the panel with: ``"ece"``
        (population-weighted, the default), ``"ace"`` (unweighted mean over
        non-empty bins — see :func:`fiducio.unweighted_calibration_error`), or
        ``None`` to omit the annotation.
    class_index:
        Optional class whose probability is compared with the observed class
        proportion (MHR for soft targets). The annotated ECE is against these
        targets, not the mean ECE against individual raters. See TwinTrack,
        Kirscher et al., MIDL 2026, https://arxiv.org/abs/2604.15950v2.

    Returns
    -------
    matplotlib.axes.Axes
        The axes the diagram was drawn on.
    """
    if metric not in (None, "ece", "ace"):
        raise ValueError(f"metric must be 'ece', 'ace' or None, got {metric!r}")
    plt = _require_matplotlib()
    curve = reliability_curve(probs, targets, mask, ignore_index, n_bins, class_index=class_index)
    if ax is None:
        _, ax = plt.subplots(figsize=(4.5, 4.5))
    return _draw_reliability(ax, curve, class_index=class_index, title=title, metric=metric)