Showing points coordinate in plot in Python
22,297
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()
![Admin](/assets/logo_square_200-5d0d61d6853298bd2a4fe063103715b4daf2819fc21225efa21dfb93e61952ea.png)
Author by
Admin
Updated on July 09, 2022Comments
-
Admin almost 2 years
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.