我正在嘗試向散點圖添加注釋,但它沒有出現,我不明白為什么。
例子:
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()
結果:

如何將注釋添加到散點圖?
uj5u.com熱心網友回復:
如果您將 line 替換fig = figure(figsize=(16, 8), dpi=80)為
fig, ax = plt.subplots(figsize=(16, 8), dpi=80)
它會起作用。您尚未在上面的示例中定義要注釋的軸。
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/364272.html
