以下脚本生成带有注释数据点的散点图。我想从图中删除圆圈标记,只显示标签。
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)
答案 0 :(得分:1)
有两种选择。 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中相同的轴限制):