简体   繁体   中英

python statsmodels ARMA plot_predict

I'm using statsmodels to compute a ARMA model with forecast. I want to change the color of the trend but I get an error:

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'

the plotting code:

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

This example is based on the example code of plot_predict from statsmodels ' documentation:

Here I use the mpl.rc_context() to temporarily change the color cycle for the figure.

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)

It's probably a little hackish, but it should solve your problem:

情节

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM