Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Save plots generated from fbprophet in Python

I'm trying to export the plots generated by facebook prophet methods such as model.plot_components() and model.plot() . However, I have dug the entire Internet and all instructions use the matplotlib method of building the plot from the ground up and then save, etc. For me, it's not possible or very hard in this case because I don't know how to plot those fbprophet functions using plain matplotlib.

Is there a general method to export an existing figure object to a .png file?

like image 478
Alice_inwonderland Avatar asked Jul 29 '26 22:07

Alice_inwonderland


1 Answers

You may use m.plot_components(forecast).savefig('filename.png') function.

df = pd.read_csv(DataFile)
m = Prophet()
m.fit(df)
future = m.make_future_dataframe(periods=365)
forecast = m.predict(future)
m.plot_components(forecast).savefig('1.png')
like image 91
patapon Avatar answered Jul 31 '26 13:07

patapon



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!