Home > Blockchain >  Adding annotates to scatter plots - don't work
Adding annotates to scatter plots - don't work

Time:11-24

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:

enter image description here

How can I add the annotate to the scatter plot ?

CodePudding user response:

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.

  • Related