Search code examples
pythonmatplotlibfacebook-prophet

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?


Solution

  • 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')