4

I want to label every dot I plot in python, and I didn't find a proper way to do it.

Assuming I have two lists of n elements called a and b, I print them this way :

    plt.figure()
    plt.grid()
    plt.plot(a , b , 'bo')
    plt.show()

I want to label every point with "Variable k" with k ranging from 1 to n obviously. Thanks for your time

4

2 Answers 2

1

You can use the label plot parameter

x = np.random.random(3)
y = np.random.random(3)
z = np.arange(3)
colors = ["red", "yellow", "blue"]
c = ["ro", "yo", "bo"]

for i in z:
    plt.plot(x[i], y[i], c[i], label=colors[i] + ' ' + str(i))
plt.legend()

enter image description here

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

Comments

1

Here is the best way of doing it I found :

plt.figure()
plt.scatter(a,b)
labels = ['Variable {0}'.format(i+1) for i in range(n)]
for i in range (0,n):
    xy=(a[i],b[i])
    plt.annotate(labels[i],xy)
plt.plot()

More infos : Matplotlib: How to put individual tags for a scatter plot

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.