Fill_between在matplotlib上给出类型错误

时间:2015-01-07 16:57:25

标签: python matplotlib

我有下图:

enter image description here

此代码生成的内容:

def graph(seconds,now, dayold, threedayold,weekold):
    dis=4*24*60*60
    x = np.array(seconds[-dis:])

    ynow = np.array(now)
    yday = np.array(dayold)
    y3day = np.array(threedayold)
    yweek = np.array(weekold)
    plt.plot(x,ynow, 'blue')
    plt.plot(x,yday, 'green')
    plt.plot(x,y3day,'purple')
    plt.plot(x,yweek, 'red')
#   plt.fill_between(x,ynow,yday,color='lightblue')
#   plt.fill_between(x,yday,y3day,color='green')
#   plt.fill_between(x,y3day,yweek,color='purple')
#   plt.fill_between(x,yweek,[0] *len(seconds),color='red')
    currenttime=int(seconds[0])
    lastweek=myround(currenttime-7*24*3600)
    plt.xlim(lastweek, currenttime)
    plt.ylim(ymax=100)
    ticks=np.arange(lastweek,currenttime,24*3600)
    labels=[time.strftime("%a", time.gmtime(x)) for x in ticks]
    plt.xticks(ticks,labels)
    plt.grid()
    plt.savefig('/home/joereddington/joereddington.com/stress/stress.png')

但我想要的是一个看起来更像这样的人物:

enter image description here

在我的本地计算机上,当前注释掉的行将实现此目的,但是,当我在服务器上尝试它时,我得到了:

home/joereddington/env/numpy-1.8.2-py2.6-linux-x86_64.egg/numpy/random/__init__.py:99: RuntimeWarning: compiletime version 2.6 of module 'mtrand' does not match runtime version 2.7
  from .mtrand import *
file processed
Traceback (most recent call last):
  File "plotNextActionData.py", line 59, in <module>
    graph(a[0],a[1],a[2],a[3],a[4])
  File "plotNextActionData.py", line 43, in graph
    #   plt.fill_between(x,ynow,yday,color='lightblue')
  File "/home/joereddington/env/matplotlib-1.4.0-py2.6-linux-x86_64.egg/matplotlib/pyplot.py", line 2820, in fill_between
    interpolate=interpolate, **kwargs)
  File "/home/joereddington/env/matplotlib-1.4.0-py2.6-linux-x86_64.egg/matplotlib/axes/_axes.py", line 4316, in fill_between
    x = ma.masked_invalid(self.convert_xunits(x))
  File "/home/joereddington/env/numpy-1.8.2-py2.6-linux-x86_64.egg/numpy/ma/core.py", line 2239, in masked_invalid
    condition = ~(np.isfinite(a))
TypeError: Not implemented for this type
joereddington@blout:~/joereddington.com/Jurgen/tracking$ 

我做错了什么? ...更重要的是,我该如何解决?

1 个答案:

答案 0 :(得分:1)

您传入的数据不是numpy数组,也不是列表,而对np.array的调用无法将原始数据转换为numpy数组。

例如,如何发生这种情况,请尝试

foo = set(['aa',1,2,3])
print(array(foo).__repr__())

打印array(set(['aa', 1, 2, 3]), dtype=object)