簡體   English   中英

Fill_between在matplotlib上提供類型錯誤

[英]Fill_between giving type errror on matplotlib

我有下圖:

在此處輸入圖片說明

通過以下代碼生成:

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

但是我想要的是一個看起來更像這樣的圖:

在此處輸入圖片說明

在我的本地計算機上,當前注釋掉的行可以實現此目的,但是,當我在服務器上嘗試它們時,我得到:

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$ 

我究竟做錯了什么? ...更重要的是,我該如何解決?

您傳入的數據既不是numpy數組也不是列表,並且對np.array的調用無法將原始數據轉換為numpy數組。

例如,有關此情況的嘗試,請嘗試

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

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM