plots

Functions

plot_change_points_interactive(ts, ...[, ...])

Plot a time series with indicated change points.

plot_time_series_with_change_points(ts, ...)

Plot segments with their trend change points.

plot_trend(ts, trend_transform[, segments, ...])

Plot series and trend from trend transform for this series.

seasonal_plot(ts[, freq, cycle, alignment, ...])

Plot each season on one canvas for each segment.

stl_plot(ts, period[, segments, ...])

Plot STL decomposition for segments.

plot_change_points_interactive(ts, change_point_model: ruptures.base.BaseEstimator, model: ruptures.base.BaseCost, params_bounds: Dict[str, Tuple[Union[int, float], Union[int, float], Union[int, float]]], model_params: List[str], predict_params: List[str], in_column: str = 'target', segments: Optional[List[str]] = None, columns_num: int = 2, figsize: Tuple[int, int] = (10, 5), start: Optional[str] = None, end: Optional[str] = None)[source]

Plot a time series with indicated change points.

Change points are obtained using the specified method. The method parameters values can be changed using the corresponding sliders.

Parameters
  • ts – TSDataset with timeseries data

  • change_point_model (ruptures.base.BaseEstimator) – model to get trend change points

  • model (ruptures.base.BaseCost) – binseg segment model, [“l1”, “l2”, “rbf”,…]. Not used if ‘custom_cost’ is not None

  • params_bounds (Dict[str, Tuple[Union[int, float], Union[int, float], Union[int, float]]]) – Parameters ranges of the change points detection. Bounds for the parameter are (min,max,step)

  • model_params (List[str]) – List of iterable parameters for initialize the model

  • predict_params (List[str]) – List of iterable parameters for predict method

  • in_column (str) – column to plot

  • segments (Optional[List[str]]) – segments to use

  • columns_num (int) – number of subplots columns

  • figsize (Tuple[int, int]) – size of the figure in inches

  • start (Optional[str]) – start timestamp for plot

  • end (Optional[str]) – end timestamp for plot

Notes

Jupyter notebook might display the results incorrectly, in this case try to use !jupyter nbextension enable --py widgetsnbextension.

Examples

>>> from etna.datasets import TSDataset
>>> from etna.datasets import generate_ar_df
>>> from etna.analysis import plot_change_points_interactive
>>> from ruptures.detection import Binseg
>>> classic_df = generate_ar_df(periods=1000, start_time="2021-08-01", n_segments=2)
>>> df = TSDataset.to_dataset(classic_df)
>>> ts = TSDataset(df, "D")
>>> params_bounds = {"n_bkps": [0, 5, 1], "min_size":[1,10,3]}
>>> plot_change_points_interactive(ts=ts, change_point_model=Binseg, model="l2", params_bounds=params_bounds, model_params=["min_size"], predict_params=["n_bkps"], figsize=(20, 10)) 
plot_time_series_with_change_points(ts: TSDataset, change_points: Dict[str, List[pandas._libs.tslibs.timestamps.Timestamp]], segments: Optional[List[str]] = None, columns_num: int = 2, figsize: Tuple[int, int] = (10, 5), start: Optional[str] = None, end: Optional[str] = None)[source]

Plot segments with their trend change points.

Parameters
  • ts (TSDataset) – TSDataset with timeseries

  • change_points (Dict[str, List[pandas._libs.tslibs.timestamps.Timestamp]]) – dictionary with trend change points for each segment, can be obtained from find_change_points()

  • segments (Optional[List[str]]) – segments to use

  • columns_num (int) – number of subplots columns

  • figsize (Tuple[int, int]) – size of the figure per subplot with one segment in inches

  • start (Optional[str]) – start timestamp for plot

  • end (Optional[str]) – end timestamp for plot

plot_trend(ts: TSDataset, trend_transform: Union[ChangePointsTrendTransform, LinearTrendTransform, TheilSenTrendTransform, STLTransform, List[Union[ChangePointsTrendTransform, LinearTrendTransform, TheilSenTrendTransform, STLTransform]]], segments: Optional[List[str]] = None, columns_num: int = 2, figsize: Tuple[int, int] = (10, 5))[source]

Plot series and trend from trend transform for this series.

If only unique transform classes are used then show their short names (without parameters). Otherwise show their full repr as label

Parameters
seasonal_plot(ts: TSDataset, freq: Optional[str] = None, cycle: Union[Literal['hour'], Literal['day'], Literal['week'], Literal['month'], Literal['quarter'], Literal['year'], int] = 'year', alignment: Union[Literal['first'], Literal['last']] = 'last', aggregation: Union[Literal['sum'], Literal['mean']] = 'sum', in_column: str = 'target', plot_params: Optional[Dict[str, Any]] = None, cmap: str = 'plasma', segments: Optional[List[str]] = None, columns_num: int = 2, figsize: Tuple[int, int] = (10, 5))[source]

Plot each season on one canvas for each segment.

Parameters
  • ts (TSDataset) – dataset with timeseries data

  • freq (Optional[str]) –

    frequency to analyze seasons:

    • if isn’t set, the frequency of ts will be used;

    • if set, resampling will be made using aggregation parameter. If given frequency is too low, then the frequency of ts will be used.

  • cycle (Union[Literal['hour'], typing.Literal['day'], typing.Literal['week'], typing.Literal['month'], typing.Literal['quarter'], typing.Literal['year'], int]) – period of seasonality to capture (see SeasonalPlotCycle)

  • alignment (Union[Literal['first'], typing.Literal['last']]) – how to align dataframe in case of integer cycle (see SeasonalPlotAlignment)

  • aggregation (Union[Literal['sum'], typing.Literal['mean']]) – how to aggregate values during resampling (see SeasonalPlotAggregation)

  • in_column (str) – column to use

  • cmap (str) – name of colormap for plotting different cycles (see Choosing Colormaps in Matplotlib)

  • plot_params (Optional[Dict[str, Any]]) – dictionary with parameters for plotting, matplotlib.axes.Axes.plot() is used

  • segments (Optional[List[str]]) – segments to use

  • columns_num (int) – number of columns in subplots

  • figsize (Tuple[int, int]) – size of the figure per subplot with one segment in inches

stl_plot(ts: TSDataset, period: int, segments: Optional[List[str]] = None, columns_num: int = 2, figsize: Tuple[int, int] = (10, 10), plot_kwargs: Optional[Dict[str, Any]] = None, stl_kwargs: Optional[Dict[str, Any]] = None)[source]

Plot STL decomposition for segments.

Parameters
  • ts (TSDataset) – dataset with timeseries data

  • period (int) – length of seasonality

  • segments (Optional[List[str]]) – segments to plot

  • columns_num (int) – number of columns in subplots

  • figsize (Tuple[int, int]) – size of the figure per subplot with one segment in inches

  • plot_kwargs (Optional[Dict[str, Any]]) – dictionary with parameters for plotting, matplotlib.axes.Axes.plot() is used

  • stl_kwargs (Optional[Dict[str, Any]]) – dictionary with parameters for STL decomposition, statsmodels.tsa.seasonal.STL is used