Visualization

Module of visualization.

adtk.visualization.plot(ts, anomaly_true=None, anomaly_pred=None, title=None, axes=None, figsize=None, ts_linewidth=0.5, ts_alpha=0.5, ts_color=None, ts_marker='.', ts_markersize=1, at_alpha=0.5, at_color='red', at_marker_on_curve=False, at_marker='v', at_markersize=3, ap_alpha=0.5, ap_color='green', ap_marker_on_curve=False, ap_marker='o', ap_markersize=3, freq_as_period=True, curve_group='each', legend=True)[source]

Plot time series and anomalies.

Parameters:
  • ts (pandas Series or DataFrame) – Time series to plot.
  • anomaly_true (list, pandas Series, or dict, optional) – Known anomalies. If list, a list of known anomalous event time (pandas Timestamp or 2-tuple of pandas Timestamps); If pandas Series, a binary series indicating normal/anomalous; If dict, a dict of lists or Series where each key-value pair is regarded as a type of anomaly.
  • anomaly_pred (list, pandas Series, or dict, optional) – Predicted anomalies. If list, a list of known anomalous event time (pandas Timestamp or 2-tuple of pandas Timestamps); If pandas Series, a binary series indicating normal/anomalous; If dict, a dict of lists or Series where each key-value pair is regarded as a type of anomaly.
  • title (str, optional) – Title of the plot.
  • axes (matplotlib axes object, or list of axes objects, optional) – Axes to plot at. The number of axes objects should be equal to the number of plots.
  • figsize (tuple, optional) – Size of the figure.
  • ts_linewidth (float, optional) – Line width of time series curves. Default: 0.5.
  • ts_alpha (float, optional) – Transparency of time series curves. Default: 0.5.
  • ts_color (str or dict, optional) – Color of time series curves. If a dict, keys are names of series. If not given, the program will assign colors automatically. Default: None.
  • ts_marker (str or dict, optional) – Marker of time series curves. If a dict, keys are names of series. Default: “.”.
  • ts_markersize (float or dict, optional) – Marker size of time series curves. If a dict, keys are names of series. Default: 1.
  • at_alpha (float, optional) – Transparency of known anomaly markers. Default: 0.5.
  • at_color (str or dict, optional) – Color of known anomaly markers. If a dict, keys are names of anomaly types. Default: “red”.
  • at_marker_one_curve (bool, optional) – Whether to plot known anomaly on the curve. Note that it may miss anomalies that does not happen at exact time points along the time series. Default: False.
  • at_marker (str or dict, optional) – Marker of known anomalies if plot on curve. If a dict, keys are names of anomaly types. Default: “v”.
  • at_markersize (float or dict, optional) – Marker size of known anomalies if plot on curve. If a dict, keys are names of anomaly types. Default: 3.
  • ap_alpha (float, optional) – Transparency of detected anomaly markers. Default: 0.5.
  • ap_color (str or dict, optional) – Color of detected anomaly markers. If a dict, keys are names of anomaly types. Default: “green”.
  • bool, optional (ap_marker_one_curve,) – Whether to plot detected anomaly on the curve. Note that it may miss anomalies that does not happen at exact time points along the time series. Default: False.
  • ap_marker (str or dict, optional) – Marker of detected anomalies if plot on curve. If a dict, keys are names of anomaly types. Default: “o”.
  • ap_markersize (float or dict, optional) – Marker size of detected anomalies if plot on curve. If a dict, keys are names of anomaly types. Default: 3.
  • freq_as_period (bool, optional) – Whether to regard time stamps following regular frequency as time spans. E.g. time index [2010-01-01, 2010-02-01, 2010-03-01, 2010-04-01, 2010-05-01] follows monthly frequency, and each time stamp represents that month if freq_as_period is True. Otherwsie, each time stamp represents the time point 00:00:00 on the first day of that month. This is only used to determine anomaly markers when marker_on_curve is on. Default: True.
  • curve_group (str or nested list of int, optional) –

    Groups of curves to be drawn at same plots.

    If nested list, for exmaple, [[0], [1,2,5], [4,6]] means dimension #0 of time series is drawn separated, while dimensions #1, #2, #5 are drawn together in the second plot, and dimensions #4 and #6 are drawn togehter in the third plot.

    If str, ‘each’ means every dimension is drawn in a separated plot, ‘all’ means all dimensions are drawn in the same plot.

    Default: ‘each’.

  • legend (bool, optional) – Whether to show legend in the plot. Default: True.
Returns:

Axes where the plot(s) is drawn.

Return type:

matplotlib axes object or list