Reputation: 7576
I'm trying to make a colorful scatter plot based on data in an array:
plt.scatter(150, 93, c=y_pred)
Here, y_pred
is:
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)
This gives me an error:
ValueError: Invalid RGBA argument: 17
I don't understand why. The same solution works for others. Could you help me understand the error?
Upvotes: 0
Views: 475
Reputation: 152577
You only add one scatter point at x=150 ; y=93
but you try to assign 150 colors for this one value.
plt.scatter(150, 93)
It works if you pass in x
and y
that have the same shape as c
:
plt.scatter(np.random.random(150), np.random.random(150), c=y_pred)
Upvotes: 1