1

I am trying to write a program using Python 3.6 to plot a 48 points with thier x and y coordinates, and I stored their x and y coordinates in pxn and pyn lists respectively The problam that I want to add each point's Id on each point. Points IDs are stored in the list that called pidn. I wrote this code part ,

    pylab.figure()
    pylab.plot(pxn,pyn, 'r+', label='Point''s Coordinates')
    pylab.legend()
    pylab.title(' Points Plotting with  X-North Direction and Y-Direction ',       loc='center', color='Blue')
    pylab.xlabel('Y-Direction', fontsize=14, color='red')
    pylab.ylabel('X-Direction',fontsize=14, color='blue')
    pylab.grid(True)
    pylab.show()

But I don not know how to add the Ids on each point from the pidn list. Any one help me please, I am a beginer in Python .

Thanks in Advance

1 Answer 1

8

If I understand correctly, you want to show the 'point ID' on the graph. This is what would be called annotating.

import matplotlib.pyplot as plt
x = [1,2,3]
y = [1,3,2]
pid = ["ID5", "IDQ", 7]

fig, ax = plt.subplots()
ax.plot(x,y, ls="", marker="o")
for xi, yi, pidi in zip(x,y,pid):
    ax.annotate(str(pidi), xy=(xi,yi))

plt.show()

enter image description here

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

2 Comments

Thank you very much for your help
If this solves your issue, consider accepting the answer. Instead of saying 'thank you', you may just upvote (votes will be counted once you have 15 reputation points).

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.