Visualization module

This module contains functions for plotting time series. It can be imported as follows:

>>> from dtaianomaly import visualization

The functions within this module offer alternative manners to nicely plot the time series along with the ground truth or predicted anomalies.

dtaianomaly.visualization.plot_time_series_colored_by_score(X: ndarray, y: ndarray, ax: Axes = None, nb_colors: int = 100, **kwargs) Figure[source]

Plots the given time series, and color it according to the given scores. Higher scores will be colored red, and lower scores will be colored green. Thus, if the ground truth anomaly scores are passed, red corresponds to anomalies and green to normal observations.

Parameters:
  • X (np.ndarray of shape (n_samples, n_attributes)) – The time series to plot

  • y (np.ndarray of shape (n_samples)) – The scores, according to which the plotted data should be colored.

  • ax (plt.Axes, default=None) – The axes onto which the plot should be made. If None, then a new figure and axis will be created.

  • nb_colors (int, default=100) – The number of colors to use for plotting the time series.

  • **kwargs – Arguments to be passed to plt.Figure(), in case ax=None.

Returns:

fig – The figure containing the plotted data.

Return type:

plt.Figure

Notes

Each segment in the time series will be plotted independently. Thus, for time series with many observations, plotting the data using this method can cost a huge amount of time.