I have a scatter plot with some toy data.
I want to draw a label next to a given point with the color of the point.
Toy example:
x = 100*np.random.rand(5,1)
y = 100*np.random.rand(5,1)
c = np.random.rand(5,1)
fig, ax = plt.subplots()
sc = plt.scatter(x, y, c=c, cmap='viridis')
# I want to annotate the third point (idx=2)
idx = 2
ax.annotate("hello", xy=(x[idx],y[idx]), color='green',
xytext=(5,5), textcoords="offset points")
plt.show()
I need to somehow get the color of this point and change my color='green'
part for color=color_of_the_point
How can I get the color of a point in a scatter plot?
The color vector c
is transformed to a colormap, and it can also have further modifications such as normalization or alpha value.
sc has a method for retrieving the coordinates of the points:
sc.get_offsets()
So it would be logical to also have a method for getting the color of the points but I could not find such method.