简体   繁体   English

PyPlot:基于目标值的彩色散点图数据

[英]PyPlot: color scatter plot data based on target value

I have a data frame with 2 dimensions.我有一个二维数据框。 ie IE

data = [[  7.08535569   5.20423916]
 [ -6.12292297  -9.79831639]
 [ -0.14405156   0.02112219]
 ...
 [ -2.93838878   2.4744518 ]
 [  8.07134259 -10.8165695 ]
 [  5.14161567   2.68737039]]

I also have a target value for each index ie我也有每个索引的目标值,即

target = [-1, 1, 1, -1 ... -1, 1, -1, -1]

What is the easiest way to use PyPlot to color code the points based on their target value?使用 PyPlot 根据目标值对点进行颜色编码的最简单方法是什么?

Currently I have目前我有

X = data[:,0]
y = data[:,1]

plt.plot(X, y, 'ro')
plt.show()

Use scatter , which accepts additional arguments for color map:使用scatter ,它接受颜色图的其他参数:

...

data = [[  7.08535569   5.20423916]
 [ -6.12292297  -9.79831639]
 [ -0.14405156   0.02112219]
 ...
 [ -2.93838878   2.4744518 ]
 [  8.07134259 -10.8165695 ]
 [  5.14161567   2.68737039]]

...

plt.scatter(x, y, c=target, s=500, cmap='gray')
plt.show()

...

References:参考:

Matplotlib scatterplot; Matplotlib 散点图; colour as a function of a third variable 颜色作为第三个变量的函数

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM