-1

The following script generates a scatter plot with annotated data points. I'd like remove circle markers from the plot and just show the labels.

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)

enter image description here

YNR
  • 867
  • 2
  • 13
  • 28
  • 1
    Don't call `ax.scatter`? Or if you do want to remove a point after you have called `ax.scatter`, see the duplicate below – DavidG Apr 24 '18 at 15:05
  • Possible duplicate of [Removing a dot in a scatter plot with matplotlib](https://stackoverflow.com/questions/32965180/removing-a-dot-in-a-scatter-plot-with-matplotlib) – DavidG Apr 24 '18 at 15:08
  • @DavidG when I remove `ax.scatter()` nothing will be shown. I also tried `ax.remove()` that shows empty plot. – YNR Apr 24 '18 at 15:42

1 Answers1

1

There are 2 options. 1) don't call ax.scatter. This does mean you have to set the axes limits yourself in order to see the points.

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()

or option 2) Call ax.scatter but remove the LineCollections that are added by doing:

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()

Both methods give the same result (provided you set the same axis limits in option 1 as you get in option 2):

enter image description here

DavidG
  • 24,279
  • 14
  • 89
  • 82