Python Matplotlib颜色分配错误?
我试图根据数组中的数据绘制一个彩色散点图:Python Matplotlib颜色分配错误?,python,matplotlib,plot,scatter-plot,Python,Matplotlib,Plot,Scatter Plot,我试图根据数组中的数据绘制一个彩色散点图: 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,
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:无效的RGBA参数:17
我不明白为什么。同样的解决方案也适用于。您能帮我理解错误吗?您只需在
x=150处添加一个分散点;y=93
但您尝试为此值指定150种颜色
plt.scatter(150, 93)
如果您传入与c
形状相同的x
和y
,则此功能有效:
plt.scatter(np.random.random(150), np.random.random(150), c=y_pred)