Module for generating interactive prediction plots.
This module provides the PredictionFigure class and make_plot function to visualize time series forecasting results, including actual values, predictions, and performance metrics.
Render the figure into a standalone HTML page via a Jinja2 template.
make_plot
plots.plotter.PredictionFigure.make_plot()
Generate the Plotly figure with traces and annotations.
Traces added (always): - Total system load — actual (training window, clipped to visible range) - Total system load — model prediction (training + forecast, clipped) - Actual (last week) — time-shifted actual for seasonality context
Traces added (when data is available): - Benchmark Forecast (e.g., ENTSOE) — if future_forecast key present - Actual (test / ground truth) — if test_actual key present
The X-axis is fixed to [end_training − 1 day, future_pred.max() + 1 h] so the full forecast window is always visible, including in genuine-future mode where future_actual is an empty Series. Only the data slice in that window is serialised into the Plotly JSON, keeping HTML output small.
Render the figure into a standalone HTML page via a Jinja2 template.
The default template wraps the Plotly figure in a minimal HTML skeleton with the figure title as <title>. Provide template_path to substitute a custom Jinja2 template that receives the variable fig (an HTML fragment) and title.
If True (default), write the figure to output_path. Pass False to obtain a figure without any disk side-effect (used by the multitask pipeline, where many figures are produced per run and the auto-write would otherwise overwrite the same file repeatedly).
Plot actual vs predicted combined values for model comparison.
This function creates an interactive Plotly figure comparing ground truth with predictions from three different forecasting models: baseline, covariate-enhanced, and custom LightGBM. The plot includes interactive hover information and can be saved as a standalone HTML file.
Safety-Critical Features
Interactive visualization for model validation
Supports HTML export for audit trails
Shows all models simultaneously for easy comparison
Interactive time series plot with outliers and optional bounds.
This function generates an interactive Plotly figure that visualizes the time series data from the pipeline, highlighting any detected outliers. Regular data points are shown in light grey, while outliers are marked in red. When config.bounds is set, two horizontal reference lines in lightblue are added per plot — one for the lower bound and one for the upper bound — to indicate the acceptable value range for that target.
The plot title includes the percentage of outliers detected for each target variable.
The explicit targets argument takes precedence when provided. When omitted, config.targets is used — the supported path for standalone/notebook usage where the config carries the resolved target list (e.g. ConfigEntsoe with explicit targets). Pipeline-internal callers (PlottingMixin) always pass task.run_state.targets explicitly after prepare_data has run.
Configuration object carrying bounds (optional list of (lower, upper) tuples, one per target, in the same order as targets). config.targets is used when the targets argument is None — the supported standalone/notebook path.
Resolved list of target column names. When provided, takes precedence over config.targets. When omitted, config.targets is used — a supported convenience for callers (e.g. notebooks) where the config already carries the resolved target list.
None
Returns
Name
Type
Description
None
None. Displays one interactive Plotly figure per target variable.
Examples
import pandas as pdimport numpy as npfrom types import SimpleNamespacefrom spotforecast2.plots.plotter import plot_with_outliers# Create synthetic datadates = pd.date_range("2023-01-01", periods=100, freq="h", tz="UTC")data = pd.DataFrame({"target1": np.random.rand(100) *100,"target2": np.random.rand(100) *50,}, index=dates)# Introduce outliersdata.loc[dates[10], "target1"] =300# Outlier in target1data.loc[dates[20], "target2"] =150# Outlier in target2df_pipeline = data.copy()df_pipeline.loc[[dates[10], dates[20]], ["target1", "target2"]] = np.nan# Config with bounds; targets passed explicitlyconfig = SimpleNamespace(bounds=[(-10, 200), (0, 100)])plot_with_outliers(df_pipeline, data, config, targets=["target1", "target2"])# Standalone path: config.targets is used when targets kwarg is omittedconfig2 = SimpleNamespace(bounds=None, targets=["target1", "target2"])plot_with_outliers(df_pipeline, data, config2)