1

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.

1
  • Sort your data by LOC score before plotting. Commented May 28, 2018 at 8:15

1 Answer 1

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

plt.scatter(df.x, df.y, s=8, c=df.lof)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.