python 状态模型的 ARMA plot_predict

python statsmodels ARMA plot_predict

我正在使用 statsmodels 来计算带有预测的 ARMA 模型。我想更改趋势的颜色,但出现错误:

fig = arma_mod30.plot_predict('2011', '2015', color='#FF6600', dynamic=True, ax=ax, plot_insample=False) TypeError: plot_predict() got an unexpected keyword argument 'color'

绘图代码:

 fig, ax = plt.subplots(figsize=(12, 8))
 ax = d.ix['2009':].plot(ax=ax,label='Trend',color='#0000FF')
 fig = arma_mod30.plot_predict('2011', '2018', color='#FF6600',  dynamic=True, ax=ax, plot_insample=False)
 plt.title('Forecast Trend')
 plt.xlabel('year')
 plt.ylabel('value')
 plt.savefig('Output.png')

此示例基于 statsmodels 文档中 plot_predict 的示例代码:

这里我使用mpl.rc_context()临时改变图形的颜色循环

with mpl.rc_context():
    mpl.rc('axes', color_cycle=['#0000FF', '#FF6600'])
    dta = sm.datasets.sunspots.load_pandas().data[['SUNACTIVITY']]
    dta.index = pd.DatetimeIndex(start='1700', end='2009', freq='A')
    res = sm.tsa.ARMA(dta, (3, 0)).fit()
    fig, ax = plt.subplots()
    ax = dta.ix['1950':].plot(ax=ax)
    fig = res.plot_predict('1990', '2012', dynamic=True, ax=ax,
                           plot_insample=False)

这可能有点老套,但应该可以解决您的问题: