如何从文本注释中删除数据点?

How remove data points from text annotate?

以下脚本生成带有注释数据点的散点图。我想从图中删除圆圈标记,只显示标签。

fig, ax = Plot.subplots()
ax.scatter(Y0_mean, Y1_mean)
for i, txt in enumerate(features.playerCountry.unique()):
    country_name = countries_code[countries_code.CountryCode == txt] 
                   ['ctr'].values[0].lower()
    ax.annotate(country_name, (Y0_mean[i], Y1_mean[i]), xytext=(Y0_mean[i], 
               Y1_mean[i]), size=5)

ax.legend(fontsize=8)
fig.savefig(figPath + 'LocationAwareMeanFeatures_ctr'+str(lr), dpi=300)

有2个选项。 1) 不要调用 ax.scatter。这确实意味着您必须自己设置坐标轴限制以便查看点。

y=[2.56422, 3.77284,3.52623,3.51468,3.02199]
x=[0.15, 0.3, 0.45, 0.6, 0.75]
n=[58,651,393,203,123]

fig, ax = plt.subplots()
# ax.scatter(x, y)

for i, txt in enumerate(n):
    ax.annotate(txt, (x[i],y[i]))

ax.set_ylim(2.5,4)

plt.show()

或选项 2) 调用 ax.scatter 但删除通过执行以下操作添加的 LineCollections:

y=[2.56422, 3.77284,3.52623,3.51468,3.02199]
x=[0.15, 0.3, 0.45, 0.6, 0.75]
n=[58,651,393,203,123]

fig, ax = plt.subplots()
points = ax.scatter(x, y)

for i, txt in enumerate(n):
    ax.annotate(txt, (x[i],y[i]))

points.remove()

plt.show()

两种方法给出相同的结果(前提是您在选项 1 中设置的轴限制与在选项 2 中设置的相同):