0
votes

I'm trying to plot an array of coordinates using matplotlib. x & y are two arrays with x and y coordinates.
Sample Data:

x = [489.99378204345703, 424.4607162475586, 665.4505157470703, 665.1176452636719]

y = [709.4012403488159, 253.38330745697021, 519.5582628250122, 519.5164632797241]

This is the code I'm using to plot

im = plt.imread(p_transform_path)
implot = plt.imshow(im)
for p,q in zip(x,y):
    x_cord = x[p]
    y_cord = y[q]
    plt.scatter([x_cord], [y_cord])
plt.show()

p_transform_path is the path of the image on which I'm plotting the coordinates.

This is the error message:

x_cord = x[p]
TypeError: list indices must be integers or slices, not numpy.float64
1

1 Answers

3
votes
im = plt.imread(p_transform_path)
implot = plt.imshow(im)
for p,q in zip(x,y):
    x_cord = p # try this change (p and q are already the coordinates)
    y_cord = q
    plt.scatter([x_cord], [y_cord])
plt.show()