arundo / adtk

A Python toolkit for rule-based/unsupervised anomaly detection in time series
https://adtk.readthedocs.io
Mozilla Public License 2.0
1.06k stars 143 forks source link

How to save the figure for the plotting result? #128

Open isunix opened 3 years ago

isunix commented 3 years ago

How to save the figure for the plotting result?

earthgecko commented 3 years ago

Hi @isunix

From one user to another. I wanted to do the same.

I have a fork with that single change that allows the plot to be save as an image: https://github.com/earthgecko/adtk/commit/895c517927d8eebbd37db9a82f772285d6a9e68e

This change simply adds the save_to_file parameter to plot function in the _visualization.py.

save_to_file: str, optional
    The full path and filename where to save the plot as a png image.
    Default: "".

To save a plot to file simply call plot with the save_to_file parameter set:

save_to_file = '/tmp/plot-image.png'
title = 'my adtk graph'
plot(s, anomaly=anomaly_df, anomaly_color='red', title=title, save_to_file=save_to_file)

If you want to install the fork (take care to use the appropriate pip version for your environment):

git clone https://github.com/earthgecko/adtk.git
cd adtk/
git checkout develop
pip install ./

I am only responding as there is very little activity on this project, hence I did not go to the trouble of pull requesting this change as there seemed to be little point.