鱼C论坛

 找回密码
 立即注册
查看: 920|回复: 1

尝试plt时间序列移动平均值时报错

[复制链接]
发表于 2018-12-2 16:57:51 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
其中一个时间序列:

                    宁沪高速
2015-06-01    0.889979
2015-06-02    0.905299
2015-06-03    0.948019
2015-06-04    0.936253
2015-06-05    0.959451
2015-06-08    1.001514
2015-06-09    1.003785
2015-06-10    0.996485
2015-06-11    0.981700
2015-06-12    1.042110
2015-06-15    1.152470
2015-06-16    1.142535
2015-06-17    1.121491
2015-06-18    1.113738
2015-06-19    1.053950
2015-06-23    1.045791
2015-06-24    1.070320
2015-06-25    1.007301
2015-06-26    0.935514
2015-06-29    0.954426
2015-06-30    0.962283
2015-07-02    0.863278
2015-07-03    0.804982
2015-07-06    0.843035
2015-07-07    0.819140
2015-07-08    0.787451
2015-07-09    0.823873
2015-07-10    0.871263
2015-07-13    0.908293
2015-07-14    0.865360

代码:
for i in stationary_pair.columns :
    x=1
    #定义移动天数
    j=10
    temp=np.log(stationary_pair.loc[:,i]/stationary_pair.loc[:,i].shift(1))
    temp1=temp.rolling(j)
    plt.figure(num=x,figsize=(25,10))
    plt.plot(temp)
    plt.axhline(temp.mean(), color='black')
    plt.axhline(temp1.mean(), color='black')
    plt.axhline(temp1.mean()+temp1.std(), color='red')
    plt.axhline(temp1.mean()-temp1.std(), color='green')
    plt.title(i,fontproperties='SimHei',fontsize=15)
    plt.show()
    x+=1

报错:
ValueError                                Traceback (most recent call last)
<ipython-input-79-1670db8e6fba> in <module>()
     26     plt.plot(temp)
     27     plt.axhline(temp.mean(), color='black')
---> 28     plt.axhline(temp1, color='black')
     29     plt.axhline(temp1.mean()+temp1.std(), color='red')
     30     plt.axhline(temp1.mean()-temp1.std(), color='green')

~\Anaconda3\lib\site-packages\matplotlib\pyplot.py in axhline(y, xmin, xmax, hold, **kwargs)
   2693                       mplDeprecation)
   2694     try:
-> 2695         ret = ax.axhline(y=y, xmin=xmin, xmax=xmax, **kwargs)
   2696     finally:
   2697         ax._hold = washold

~\Anaconda3\lib\site-packages\matplotlib\axes\_axes.py in axhline(self, y, xmin, xmax, **kwargs)
    716         self._process_unit_info(ydata=y, kwargs=kwargs)
    717         yy = self.convert_yunits(y)
--> 718         scaley = (yy < ymin) or (yy > ymax)
    719
    720         trans = self.get_yaxis_transform(which='grid')

~\Anaconda3\lib\site-packages\pandas\core\generic.py in __nonzero__(self)
   1574         raise ValueError("The truth value of a {0} is ambiguous. "
   1575                          "Use a.empty, a.bool(), a.item(), a.any() or a.all()."
-> 1576                          .format(self.__class__.__name__))
   1577
   1578     __bool__ = __nonzero__

ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().

小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2018-12-2 20:12:45 | 显示全部楼层
尝试吧Series类型转化为ndarray
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2026-1-11 08:39

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表