I have a data frame with 2 dimensions. 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?
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:
...
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; colour as a function of a third variable
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.