Issue
When doing multiple scatterplots, I want the colors of the new plotted points to be in line with the same colorbar. I have my base plot (colors are stored in y
array):
im = ax.scatter(embs[:,0],
embs[:,1],
edgecolor='k',
linewidth=0.2,
c=y
)
Now I want to highlight a specific point, by plotting a red contour (I'm highlighting the yellow point top right):
ax.scatter(embs[5715][0],
embs[5715][1],
edgecolor='red',
linewidth=0.3,
c=y[5715]
)
The problem is that its color now won't agree with the original one:
Solution
One easy way to fix this is to pass the norm
of the object returned by your first scatter
call as the norm
of the second call.
This ensures that the range of data used for the first scatter plot is respected for the second one
e.g.
import matplotlib.pyplot as plt
import numpy as np
x, y = np.random.normal(size=(2, 1000))
c = x ** 2 + y ** 2
cb = plt.scatter(x, y, c=c, ec="k")
plt.scatter(x[777], y[777], c=c[777], ec="r", norm=cb.norm)
plt.colorbar(cb)
plt.show()
which will give e.g.
Answered By - tomjn
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.