label plot points

Hello,
I have the following code:

···

---------------------------------------------------------------
from pylab import *
import matplotlib.pyplot as plt

x = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29]
y = [20, 24, 8, 4, 12, 22, 31, 25, 15, 28, 12, 27, 22, 22, 27, 14, 32, 28, 8, 17, 2, 8, 29, 13, 14, 20, 11, 28, 8]

point_labels = ['A=1', 'A=1', 'A=1', 'A=1', 'A=1', 'A=1', 'A=1', 'A=1', 'A=1', 'A=1', 'A=1', 'A=1', 'A=1', 'A=1', 'A=1', 'A=1', 'A=1', 'A=1', 'A=1', 'A=1', 'A=1', 'A=1', 'A=1', 'A=1', 'A=1', 'A=1', 'A=1', 'A=1', 'A=1', 'A=1']

fig = plt.figure()
ax = fig.add_subplot(111)

ax.plot(x, y, 'go-')
ax.grid(True)

# rotates and right aligns the x labels, and moves the bottom of the
# axes up to make room for them
fig.autofmt_xdate()

# set x and y labels
plt.xticks(range(0, 40, 1))

plt.yticks(range(0, 40, 1))
plt.show()
---------------------------------------------------------------

I would like to label all (x[i],y[i]) points in the plot with point_labels[i].

Is it possible to label all points in a plot?

Thank you in advance.

Use plt.text (x, y, point_labels ) or something along those lines.

Jose

···

On Saturday 21 Aug 2010 08:00:33 xyz wrote:

I would like to label all (x[i],y[i]) points in the plot with
point_labels[i].

Is it possible to label all points in a plot?

With plt.text() the plot line is sometimes covered by the point labels. Is there any option which recognise a collusion between the line and label?

from pylab import *
import matplotlib.pyplot as plt

x = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29]
y = [20, 24, 8, 4, 12, 22, 31, 25, 15, 28, 12, 27, 22, 22, 27, 14, 32, 28, 8, 17, 2, 8, 29, 13, 14, 20, 11, 28, 8]

point_labels = ['A=1', 'A=1', 'A=1', 'A=1', 'A=1', 'A=1', 'A=1', 'A=1', 'A=1', 'A=1', 'A=1', 'A=1', 'A=1', 'A=1', 'A=1', 'A=1', 'A=1', 'A=1', 'A=1', 'A=1', 'A=1', 'A=1', 'A=1', 'A=1', 'A=1', 'A=1', 'A=1', 'A=1', 'A=1']

fig = plt.figure()
ax = fig.add_subplot(111)

ax.set_title('The red point should be on the path')
ax.plot(x, y, 'go-')
ax.grid(True)

# rotates and right aligns the x labels, and moves the bottom of the
# axes up to make room for them
fig.autofmt_xdate()

# set x and y labels
plt.xticks(range(0, 40, 1))

#ax.set_xticks(4.5)
plt.yticks(range(0, 40, 1))

for i, label in enumerate(point_labels):
   plt.text (x[i], y[i], label )

plt.show()

···

On 21/08/10 21:14, Jose Gómez-Dans wrote:

Use plt.text (x, y, point_labels ) or something along those lines.

Jose