简体   繁体   English

散点图颜色指向Python

[英]Scatter plot color points Python

I am trying to colour points according to their LOF (Local outlier Factor). 我试图根据他们的LOF(局部离群因子)对点进行着色。 My problem is that some points have the same coordinates and thus are plotted on top of each other. 我的问题是一些点具有相同的坐标,因此被绘制在彼此之上。 Example of this could be 这样的例子可能是

df = pd.DataFrame({
'x' : [1,1],
'y' : [1,1],
 })

lof = pd.DataFrame({
'lof' : [2,1],
})


fig= plt.figure(figsize = (4,3), dpi = 200)
plt.scatter(df.x,df.y, s = 8, c =lof.lof)
plt.show()

As It can be seen from my example I have two points on top of other with different LOF scores. 从我的例子中可以看出,我有两个点,而其他LOF得分不同。 The yellow point is drawn first, and then afterwards the purple point is drawn on top of the yellow point, making it invisible. 首先绘制黄点,然后在黄点顶部绘制紫色点,使其不可见。 Ideally, I would like my scatterplot to drawn the points with the lowest LOF score first and the points with the highest LOF score last such that the points with the highest score are visible. 理想情况下,我希望我的散点图首先绘制LOF得分最低的点,最后LOF得分最高的点,以便得分最高的点可见。

df['lof'] = lof
df.sort_values('lof', inplace=True)

plt.scatter(df.x, df.y, s=8, c=df.lof)

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

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