简体   繁体   中英

Scatter plot color points Python

I am trying to colour points according to their LOF (Local outlier Factor). 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. 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.

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

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

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.

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