2017-08-29 115 views
0

我試圖在一個陣列基於數據豐富多彩的散點圖:Matplotlib顏色分配錯誤?

plt.scatter(150, 93, c=y_pred) 

這裏,y_pred是:

array([ 5, 6, 8, 16, 21, 12, 12, 13, 6, 6, 17, 11, 6, 12, 12, 23, 6, 
     6, 15, 6, 6, 6, 6, 6, 6, 23, 22, 6, 12, 17, 6, 20, 0, 6, 
     6, 12, 12, 0, 6, 6, 6, 6, 6, 6, 5, 17, 6, 6, 11, 10, 13, 
     6, 22, 24, 23, 6, 6, 13, 6, 6, 6, 12, 9, 15, 13, 14, 6, 18, 
     1, 6, 9, 6, 6, 11, 6, 5, 16, 9, 23, 2, 14, 24, 9, 5, 9, 
     10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 1, 6, 19, 6, 23, 3, 
     20, 10, 4, 8, 9, 6, 6, 9, 22, 23, 6, 6, 11, 6, 6, 6, 22, 
     24, 14, 4, 7, 12, 6, 19, 6, 12, 3, 22, 6, 11, 6, 21, 23, 4, 
     6, 6, 6, 4, 10, 22, 15, 6, 6, 18, 6, 14, 4, 5], dtype=int32) 

這給了我一個錯誤:

ValueError: Invalid RGBA argument: 17

我不明白爲什麼。同樣的解決方案適用於others。你能幫我理解錯誤嗎?

回答

1

您只能在x=150 ; y=93上添加一個散點,但您嘗試爲此值分配150個顏色。

plt.scatter(150, 93) 

enter image description here

如果您在xy具有相同的形狀c通過它的工作原理:

plt.scatter(np.random.random(150), np.random.random(150), c=y_pred) 

enter image description here