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)
There may be several approaches, create a data frame for the annotation, group by column value and list the indexes. Set annotations in the created data frame. In this data example, more strings overlap, so we change the offset values only for the indices we do not want to overlap.
Use legend() method to avoid overlapping of labels and autopct. To display the figure, use show() method.
Dot Size. You can try to decrease marker size in your plot. This way they won't overlap and the patterns will be clearer.
I suggest that you install the adjustText package:
python -m pip install adjustText
and later follow this old Stackoverflow answer.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With