Visualization Utilities

confetti.visualizations.plot_counterfactual(original: ndarray, counterfactual: Counterfactual, channels: Sequence[int] | None = None, cam_weights: ndarray | None = None, cam_mode: str = 'none', figsize: Tuple[float, float] | None = None, title: str | None = None) None

Plot an original multivariate time series together with its counterfactual.

The counterfactual is assumed to differ from the original over a contiguous subsequence, which is highlighted in the visualization. Optional CAM information can be overlaid either as a line or as a heatmap.

Parameters:
  • original (ndarray) – Original time series with shape (timesteps, channels) or (1, timesteps, channels).

  • counterfactual (Counterfactual) – Counterfactual object whose internal counterfactual array has the same shape as original.

  • channels (sequence of int, optional) – Channel indices to plot. If None, all channels are shown.

  • cam_weights (ndarray of shape (timesteps,), optional) – CAM weights to overlay. Used when cam_mode is "line" or "heatmap".

  • cam_mode ({"none", "line", "heatmap"}, default="none") –

    Type of CAM visualization to include:

    • "none": no CAM overlay

    • "line": CAM shown as a line in each subplot

    • "heatmap": CAM shown as a separate heatmap subplot

  • figsize (tuple of float, optional) – Figure size passed to Matplotlib. If None, chosen automatically.

  • title (str, optional) – Optional title for the figure.

Raises:
  • CONFETTIDataTypeError – If the time series arrays have incompatible shapes or invalid types.

  • CONFETTIConfigurationError – If channels are invalid or if CAM settings are inconsistent.

confetti.visualizations.plot_time_series(series: ndarray | Counterfactual, channels: Sequence[int] | None = None, figsize: Tuple[float, float] | None = None, title: str | None = None) None

Plot a multivariate time series.

Parameters:
  • series (ndarray or Counterfactual) – Time series with shape (timesteps, channels) or (1, timesteps, channels).

  • channels (sequence of int, optional) – Channel indices to plot. If None, all channels are plotted.

  • figsize (tuple of float, optional) – Figure size passed to Matplotlib. If None, determined automatically.

  • title (str, optional) – Title of the figure.

Raises:
  • CONFETTIDataTypeError – If series has an unsupported shape.

  • CONFETTIConfigurationError – If channels contains invalid indices.