Search code examples
pythonpandasmatplotlibplotlystatsmodels

MatPlot Lib to Plotly


Using statsmodels ARIMA Model, I have created a forecast with the code and graphs written below. However, I want to implement this forecast into my dash app as a plotly figure. Is it possible to eighter convert the matplot figure to a plotly figure, or is there a command in StatsModels


#ARIMA FORECAST

idx = pd.date_range(df1.index[0], '2022-04-05')
df2 = df2.reindex(idx, fill_value=0)
res = ARIMA(df2, order=(15,1,15)).fit()
fig, ax = plt.subplots()
ax = df2.loc['2021-11-01':].plot(ax=ax)
plot_predict(res, '2022-03-01', '2022-05-15', ax=ax)
plt.show()

Plot

So can I eighter convert this figure into plotly, or is there a function other than plot_predict which will return a series or DF of the predicted values that are out of forecast.

Thanks!


Solution

  • Don't have your dataset, you can just call the predictions out by doing:

    res.predict(start = '2022-03-01', end = '2022-05-15')
    

    See also the help page