[英]python statsmodels ARMA plot_predict
I'm using statsmodels to compute a ARMA model with forecast. 我正在使用statsmodels来计算带有预测的ARMA模型。 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' fig = arma_mod30.plot_predict('2011','2015',color ='#FF6600',dynamic = True,ax = ax,plot_insample = False)TypeError:plot_predict()得到了一个意外的关键字参数'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: 本示例基于statsmodels
文档中的plot_predict
示例代码:
Here I use the mpl.rc_context()
to temporarily change the color cycle for the figure. 在这里,我使用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)
It's probably a little hackish, but it should solve your problem: 可能有点破烂,但是应该可以解决您的问题:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.