2016-08-23 22 views
0

我正在下面雖然數據看起來不錯錯誤matplotlib無效RGBA ARG,但我傳遞了正確的arguement我「覺得」

ValueError: to_rgba: Invalid rgba arg "['g']" to_rgb: Invalid rgb arg "('g',)" sequence length is 1; must be 3 or 4 

我將其加載到這裏的元組最後一個參數

sector_format = { 
'0': ["Materials","o",'lightcoral'], 
'1':["Information Technology","^",'g'], 
'2':[ "Financials","v",'r'], 
'3':["Consumer Discretionary","s",'c'], 
'4':["Industrials","d",'m'], 
'5':["Health Care","8",'y'], 
'6':["Energy",">",'k'], 
'7':["emerging markets","h",'lightgrey'], 
'8':["Consumer Staples","|",'lightblue'] 
} 

我在這裏使用它在那裏final_np [測試:測試+ 1,3]中包含的顏色值

ax1.plot(final_np[prior_test:test,1],final_np[prior_test:test,2],lw = 0.5,color=final_np[test:test+1,3],marker=r"$ {} $".format(final_np[test:test+1,0]),markersize=final_np[test:test+1,6]) 

如果我打印出來的測試數據(這裏是一個例子)

print("test data ", final_np[prior_test:test,1],final_np[prior_test:test,2],final_np[test:test+1,0],final_np[test:test+1,6],final_np[test:test+1,3]) 

我得到的值傳遞給顏色爲'r'這似乎對我來說確定。這裏是一個測試打印的例子

test data [datetime.date(2015, 8, 10) datetime.date(2015, 8, 14) 
datetime.date(2015, 8, 17) datetime.date(2015, 8, 21) 
datetime.date(2015, 8, 24) datetime.date(2015, 8, 28) 
datetime.date(2015, 8, 31)] [64.0 90.0 89.0 8.0 5.0 50.0 53.0] 
['^VIX'] [20] ['r'] 

我錯過了什麼?

+0

你可以把它變成一個演示問題的可運行示例嗎? – tacaswell

+0

再次嗨Tcaswell對不起,我沒有嘗試過,但很快就變得非常混亂。我希望錯誤信息包含我錯過的東西。也許它的格式不正確,我沒有看到它。我讀了matplotlib文檔,看了一下例子,看起來都很好,但顯然我已經搞砸了。再次感謝您看看這個,我明白我的問題缺乏, – theakson

+2

錯誤消息'Invalid rgba arg「['g']」'建議您傳遞一個數組,其中只有一個字符串值是期待。 – cphlewis

回答

0

@cphlewis你是一顆星!

這次讓我再次看錯誤IN DETAIL,你說得對。我做了國防部

jcolor = ''.join(final_np[test:test+1,3]) 

,並呼籲情節與

ax1.plot(final_np[prior_test:test,1],final_np[prior_test:test,2],lw = 0.5,color=jcolor,marker=r"$ {} $".format(final_np[test:test+1,0]),markersize=final_np[test:test+1,6]) 

,一切都很好在花園裏。謝謝@cphlewis

相關問題