11

I want to show the (x,y) axis of points from a 2d array in a plot.

I know that by the following codes I can draw the points

import matplotlib.pyplot as plt
plt.plot([1,2,3,4], [1,4,9,16], 'ro')
plt.axis([0, 6, 0, 20])
plt.show()

Which show me this picture: output of the above code

However, I want to show the x,y of each point near to them in the plot. Something like this Which I am looking

Thank you very much in advance.

2

1 Answer 1

19

This should do the trick:

import matplotlib.pyplot as plt
x = [1,2,3,4]
y = [1,4,9,16]
plt.plot(x, y, 'ro')
plt.axis([0, 6, 0, 20])

for i_x, i_y in zip(x, y):
    plt.text(i_x, i_y, '({}, {})'.format(i_x, i_y))

plt.show()
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.