source

plot_series

 plot_series
              (df:Union[pandas.core.frame.DataFrame,polars.dataframe.frame
              .DataFrame], forecasts_df:Union[pandas.core.frame.DataFrame,
              polars.dataframe.frame.DataFrame,NoneType]=None,
              ids:Optional[List[str]]=None, plot_random:bool=True,
              max_ids:int=8, models:Optional[List[str]]=None,
              level:Optional[List[float]]=None,
              max_insample_length:Optional[int]=None,
              plot_anomalies:bool=False, engine:str='matplotlib',
              palette:str='viridis', id_col:str='unique_id',
              time_col:str='ds', target_col:str='y', seed:int=0,
              resampler_kwargs:Optional[Dict]=None)

Plot forecasts and insample values.

TypeDefaultDetails
dfUnionDataFrame with columns [id_col, time_col, target_col].
forecasts_dfUnionNoneDataFrame with columns [id_col, time_col] and models.
idsOptionalNoneTime Series to plot.
If None, time series are selected randomly.
plot_randomboolTrueSelect time series to plot randomly.
max_idsint8Maximum number of ids to plot.
modelsOptionalNoneModels to plot.
levelOptionalNonePrediction intervals to plot.
max_insample_lengthOptionalNoneMaximum number of train/insample observations to be plotted.
plot_anomaliesboolFalsePlot anomalies for each prediction interval.
enginestrmatplotlibLibrary used to plot. ‘plotly’, ‘plotly-resampler’ or ‘matplotlib’.
palettestrviridisName of the matplotlib colormap to use.
id_colstrunique_idColumn that identifies each serie.
time_colstrdsColumn that identifies each timestep, its values can be timestamps or integers.
target_colstryColumn that contains the target.
seedint0Seed used for the random number generator. Only used if plot_random is True.
resampler_kwargsOptionalNoneKeyword arguments to be passed to plotly-resampler constructor.
For further custumization (“show_dash”) call the method,
store the plotting object and add the extra arguments to
its show_dash method.
Returnsmatplotlib or plotly figurePlot’s figure
from utilsforecast.data import generate_series
level = [80, 95]
series = generate_series(4, freq='D', equal_ends=True, with_trend=True, n_models=2, level=level)
test_pd = series.groupby('unique_id', observed=True).tail(10).copy()
train_pd = series.drop(test_pd.index)
fig = plot_series(
    train_pd,
    forecasts_df=test_pd,
    ids=[0, 3],
    plot_random=False,
    level=level,    
    max_insample_length=50,
    engine='matplotlib',
    plot_anomalies=True,
)
fig.savefig('imgs/plotting.png', bbox_inches='tight')