我收到的错误虽然数据看起来不错
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 [test:test + 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 :(得分:0)
@cphlewis你是一个明星!
这次让我再次看错了IN DETAIL,你是对的。我做了mod
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