WillianFuks / tfcausalimpact

Python Causal Impact Implementation Based on Google's R Package. Built using TensorFlow Probability.
Apache License 2.0
600 stars 72 forks source link

Best way to turn .plot() into an image? #40

Closed graingerkid closed 2 years ago

graingerkid commented 2 years ago

I'd like to use this lib as part of a Flask application but stuggling to pass it to the front end. Any suggestions?

WillianFuks commented 2 years ago

Hi @graingerkid ,

It's possible to use the option ci.plot(show=False) which keeps the matplotlib figure and axes still available. Then you can retrieve the image by running plt.gcf(). I've created this colab notebook showing how to do so.

Once you have access to the figure object then I suppose you can use the answer in this SO thread to return the image as desired.

Hopefully this helps or gives you some ideas on how to proceed.

graingerkid commented 2 years ago

Ah - that works perfectly. Thanks for taking the time. Appreciate your help and your work