Skip to content

Add an original-vs-reconstructed compare plot to AggregationResult #95

Description

@FBumann

Summary

AggregationResult exposes original, reconstructed, residuals, and accuracy as data, but there's no built-in way to visualize how well the clustering reproduces the input. Eyeballing original-vs-reconstructed is the single most common thing users do after aggregating, and today everyone hand-rolls the plotly/matplotlib code for it.

There's already a plotting precedent in the package — TuningResult.plot() (RMSE vs timesteps) — and plotly is already an optional dependency there, so a comparison plot fits naturally alongside it.

Proposal

Add a plotting helper on AggregationResult, e.g.:

agg.plot_compare(variable=None, *, kind="timeseries")  # -> plotly Figure
  • Overlays original vs reconstructed on the original time axis.
  • variable=None plots all columns (color by column); a name/list selects a subset.
  • kind="timeseries" (default) and kind="duration_curve" (sorted descending).
  • Distinguish the two series clearly (e.g. Original dotted / Reconstructed solid).
  • Faceting over slice dims (period/scenario) when present.
  • try: import plotly ... except ImportError: raise with a helpful message, matching TuningResult.plot().

This pairs with the tidy-data helper proposed in #92: compare()/to_dataframe() return the data; plot_compare() returns the ready figure built from it.

Motivation / context

Downstream, flixopt just re-added a clustering.plot.compare() wrapper (flixOpt/flixopt#734) precisely because this plot was missing — it restores functionality users lost. If the plot lived here, that wrapper would become a thin dim-name adapter (or go away), and non-flixopt users of tsam_xarray would get the same convenience.

Happy to send a PR.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions