9

I would like to draw a scatter plot with labeling. However, these labels are overlapping. How can I enhance its look so that I can see numbers better? Also, I have numbers in integer, but it shows label values in float. I am wondering why.

Looking forward to hearing back from you guys.

Here's my code:

col = df['type'].map({'a':'r', 'b':'b', 'c':'y'})
ax = df.plot.scatter(x='x', y='y', c=col)

df[['x','y','id']].apply(lambda x: ax.text(*x),axis=1)

enter image description here

4
  • 1
    From how your points are distributed I think it will be very difficult to find an automated way to make the labels not overlap. A few alternative ways of visualisation come to mind, but with the information you gave us it's hard to know if they are applicable. Can you maybe add information of what the colours of the data points and the label numbers represent? Commented Aug 18, 2017 at 5:55
  • 2
    It might be worth considering making the marker size/area proportional to the value. When the points are in dense clusters it it unlikely that the reader can resolver which labels are proportional to which points. Commented Aug 18, 2017 at 8:03
  • 7
    You may look at the adjustText package. Here would be an example question about it. Commented Aug 18, 2017 at 10:51
  • @ImportanceOfBeingErnest very nice! I especially like the example section of that github page. Commented Aug 18, 2017 at 11:29

1 Answer 1

3

I suggest that you install the adjustText package:

python -m pip install adjustText

and later follow this old Stackoverflow answer.

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.