Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Adding annotates to scatter plots – don't work

I’m trying to add annotates to scatter plot, but it don’t appear and I can’t understand why.

Example:

x = [ 6.343056,  -2.5713196 , 6.0487113 ,  10.894953  , 13.541282    , 3.64124    ,-1.7216474 , -4.916564 , -1.2961074 , 6.835421 ]
y = [11.965563,   -3.6742558,  12.373212,    9.714097 ,  -0.56607884 , 10.242817  ,0.7512899  , 2.1867976 ,  3.8110814 , 12.3270445]
t = [9, 6, 6, 4, 1, 9, 3, 9, 0, 9]


figure(figsize=(16, 8), dpi=80)
plt.scatter(x, y, c=t, cmap='viridis', alpha=0.3);
for i, tag in enumerate(t):
    
    ax.annotate("{}".format(tag), (x[i], y[i]),
                 textcoords="offset points", 
                 xytext=(0,10),
                 ha='center')
plt.colorbar();
plt.show()

Results:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

enter image description here

How can I add the annotate to the scatter plot ?

>Solution :

If you substitute line fig = figure(figsize=(16, 8), dpi=80) for

fig, ax = plt.subplots(figsize=(16, 8), dpi=80)

it will work. You haven’t defined the axis you want to annotate in your example above.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading