How to conciliate dots annotation in Matplotlib scatter plot with manual limit setting?

0 votes
asked Jan 18 by alexnesov

I'm trying to conciliate dots annotation in a Matplotlib scatter plot with a manual limit setting, but I either got an error message or I get a design problem.

Here is my code :

fig, ax = plt.subplots(figsize = (20,10)) #manual limit setting
plt.axis([-2,3,-2.5,5])
plt.scatter(x, y)
for i, txt in enumerate(n): #dot annotation ax.annotate(txt, (x[i], y[i]))

Here is a screen cap of the output (I got the final scatter plot as a small rectangle located in the left corner of a big white rectangle :

Output

I tried this also :

 fig, ax = plt.subplots(figsize = (20,10)) ax = plt.axis([-2,3,-2.5,5]) plt.scatter(x, y)
for i, txt in enumerate(n): ax.annotate(txt, (x[i], y[i]))

But of course I got the following error message (even though the chart correctly displays, but without the labels next to each corresponding dot).

AttributeError: 'list' object has no attribute 'annotate'

The error arises because my loop tries to iterate through ax = plt.axis([-2,3,-2.5,5]), which doesn't make sense indeed.

Any solution to overcome this issue ?

Thank you

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
Anti-spam verification:
To avoid this verification in future, please log in or register.
Welcome to Q&A, where you can ask questions and receive answers from other members of the community.
Website Online Counter

...