source

plot_series

 plot_series (df:Optional[~DFType]=None,
              forecasts_df:Optional[~DFType]=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:Optional[str]=None, id_col:str='unique_id',
              time_col:str='ds', target_col:str='y', seed:int=0,
              resampler_kwargs:Optional[Dict]=None, ax:Union[matplotlib.ax
              es._axes.Axes,numpy.ndarray,ForwardRef('plotly.graph_objects
              .Figure'),NoneType]=None)

Plot forecasts and insample values.

TypeDefaultDetails
dfOptionalNoneDataFrame with columns [id_col, time_col, target_col].
forecasts_dfOptionalNoneDataFrame 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’.
paletteOptionalNoneName of the matplotlib colormap to use for the plots. If None, uses the current style.
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.
axUnionNoneObject where plots will be added.
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)
plt.style.use('ggplot')
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')