10

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.

Behnam
  • 113
  • 1
  • 1
  • 6

1 Answers1

18

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()
Mason McGough
  • 532
  • 5
  • 13