Jellyse
Jellyse

Reputation: 863

Scatter plot move labels

I created a map of some large ports. With 'x' and 'y' latitude and longitude and 'text' the port names.

x,y = map(lonA, latA)
map.scatter(x, y, s=Size, c=color, marker='o', label = 'Ports',alpha=0.65, zorder=2)
for i in range (0,n):
  plt.annotate(text[i],xy=(x[i],y[i]),ha='right')

The dots I plotted (bigger dots for bigger ports) overlap with the labels. How do I plot them a little further away to increase readability? enter image description here

Upvotes: 0

Views: 1741

Answers (2)

Jellyse
Jellyse

Reputation: 863

@KiralySandor you were right, but you need to change textcoordinates to data.

for i in range (0,n):
  plt.annotate(text[i],xy=(x[i],y[i]),textcoords='data',xytext=(x[i]-9000,y[i]),ha='right')

enter image description here

Now the names are slighlty more to the left.

Upvotes: 0

Zsolt Diveki
Zsolt Diveki

Reputation: 159

You can use the xytext parameter to adjust the text position:

plt.annotate(text[i],xy=(x[i],y[i]),xytext=(x[i]+10,y[i]+10), ha='right')

Here I added 10 to your xy position. For more you can look up the suggestions here: https://matplotlib.org/users/annotations_intro.html

Upvotes: 1

Related Questions