fusionlab.plot.evaluation.plot_mean_interval_width

fusionlab.plot.evaluation.plot_mean_interval_width(y_lower, y_upper, miw_values=None, metric_kws=None, kind='summary_bar', output_idx=None, hist_bins='auto', hist_color='mediumpurple', hist_edgecolor='black', figsize=(10, 6), title='Mean Interval Width (Sharpness)', xlabel=None, ylabel=None, bar_color='mediumpurple', bar_width=0.8, score_annotation_format='{:.4f}', show_score=True, show_grid=True, grid_props=None, ax=None, verbose=0, **kwargs)[source]

Visualise Mean Interval Width (MIW) – a simple sharpness measure equal to the average distance between lower and upper prediction‐ interval bounds.

Two complementary views are implemented:

  • ‘widths_histogram’ – distribution of individual interval widths for a chosen output.

  • ‘summary_bar’ – bar chart of the averaged width (overall or one bar per output).

Parameters:
  • y_lower (ndarray) – Lower‑bound quantile (e.g. 0.05 or 0.10) for an uncertainty interval. Shape must mirror y_true. Required by coverage,

  • y_upper (ndarray) – Upper‑bound quantile (e.g. 0.95 or 0.90) paired with y_lower.

  • miw_values (float or ndarray, optional) – Pre‑computed MIW score(s). If supplied the helper skips the internal call to fusionlab.metrics.mean_interval_width_score().

  • metric_kws (dict, optional) – Extra keyword arguments forwarded to fusionlab.metrics.mean_interval_width_score().

  • kind ({'widths_histogram', 'summary_bar'},) – default 'summary_bar' Select the visualisation style.

  • output_idx (int, optional) – Output dimension to plot when kind='widths_histogram' on multi‑output data.

  • hist_bins (int | sequence | str, default :class:``’auto’:class:``)

  • hist_color (str, default :class:``’mediumpurple’:class:``)

  • hist_edgecolor (str, default :class:``’black’:class:``) – Styling options for the histogram.

  • figsize (tuple of float, optional) – Size of the figure in inches (width, height). If omitted the

  • title (str, optional) – Main title for the figure. If None, a context‑aware default

  • xlabel (str, optional) – Label for the x‑axis. If None, a function‑specific default is

  • ylabel (str, optional) – Label for the y‑axis. If None, a context‑sensitive default is

  • bar_color (str or list of str, optional) – Bar face‑colour(s). Accepts any Matplotlib‑recognised colour

  • bar_width (float, default 0.8)

  • score_annotation_format (str, default '{:.4f}') – Python format string used for numeric annotations. Examples:

  • show_score (bool, default True) – Display the mean width on the histogram title.

  • show_grid (bool, default True)

  • grid_props (dict, optional) – Keyword arguments forwarded to Axes.grid for fine‑grained

  • ax (matplotlib.axes.Axes, optional) – Existing Matplotlib axes to draw on. If None, a new figure

  • verbose (int, default 0) – Verbosity level. 0 ⇒ silent, 1 ⇒ basic info, 2+ ⇒ debug

  • **kwargs – Additional keyword arguments passed directly to the underlying Matplotlib primitives (plot, scatter, bar,

Returns:

Axes containing the MIW visualisation.

Return type:

matplotlib.axes.Axes

Notes

For a single observation the interval width is simply

\[w_i \;=\; u_i \;-\; \ell_i ,\]

where \(u_i\) and \(\ell_i\) are the upper and lower bounds. The mean interval width over N samples is

\[\text{MIW} \;=\; \frac{1}{N}\sum_{i=1}^{N} w_i.\]

Lower MIW indicates a sharper forecast, but should always be interpreted together with coverage diagnostics.

Examples

>>> import numpy as np, matplotlib.pyplot as plt
>>> from fusionlab.plot.evaluation import plot_mean_interval_width
>>> rng = np.random.default_rng(1)
>>> y_l = rng.normal(loc=-1.0, scale=.5, size=200)
>>> y_u = y_l + rng.uniform(1.5, 2.5, size=200)
>>> plot_mean_interval_width(
...     y_lower=y_l, y_upper=y_u, kind='widths_histogram',
...     figsize=(8, 4))
>>> plt.show()

See also

fusionlab.metrics.mean_interval_width_score

Numeric computation of MIW.

fusionlab.plot.evaluation.plot_coverage

Shows how many observations fall inside the intervals.

fusionlab.plot.evaluation.plot_weighted_interval_score

Combines width with calibration penalties.

References