0

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

2 Answers 2

1

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

Sign up to request clarification or add additional context in comments.

6 Comments

I tried it but doesn't work. :( Even if I do +100 (xytext=(x[i]+100,y[i]+100)) there's no difference...
Is it possible that your x and y axes cover a huge range, like millions, where a 100 movement would be small?
No normally not. My axes are in degrees latitude and longitude, so +10 would be +10 degrees. Normally, they should be moving very far, but they don't move at all.
I do not know what object is map in your script, but you are using a scatter method on it. Is it possible to use the annotate method on it too? map.annotate instead of plt.annotate?
It's just the name. If I do map.annotate, it doesn't print any labels
|
0

@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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.