Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Showing points coordinate in plot in Python [duplicate]

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.

like image 365
Behnam Avatar asked Sep 19 '18 14:09

Behnam


People also ask

How do you keep plots from overlapping in Python?

Dot Size. You can try to decrease marker size in your plot. This way they won't overlap and the patterns will be clearer.

How do you plot overlapping data in Python?

Set the figure size and adjust the padding between and around the subplots. Initialize a variable overlapping to set the alpha value of the line. Plot line1 and line2 with red and green colors, respectively, with the same alpha value. To display the figure, use show() method.


1 Answers

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()
like image 68
Mason McGough Avatar answered Sep 30 '22 03:09

Mason McGough