What's the easiest way to format this array data so that I can connect the points on the graph iterating, assuming each line contains x and y coordinates of a single point?
import matplotlib.pyplot as plt
(...)
<class 'numpy.ndarray'>
[-22.58343371 7.97162262]
[-49.08400669 -28.64111278]
[-71.47754547 -25.78248676]
[-46.27120899 -21.72541444]
[ 43.6158669 109.61815799]
[-22.58343371 7.97162262]
(...)
plt.plot(x, y, color='orange')
Sorry, below is almost complete code (order is calculated by another alghoritm) corrected thanks to Quang Hoang's comment. This is obviously part of the solution to the well known tsp problem. The point, of course, is to connect the points according to the correct order in the list which in this case is: (0, 2, 1, 3, 4, 0).
from sklearn.decomposition import PCA
import matplotlib.pyplot as plt
import numpy as np
n = 5
order = (0, 2, 1, 3, 4, 0)
distances = [[0, 39, 22, 59, 54, 33, 57, 32, 89, 73, 29, 46],
[39, 0, 20, 20, 81, 8, 49, 64, 63, 84, 10, 61],
[22, 20, 0, 39, 74, 18, 60, 44, 71, 73, 11, 46],
[59, 20, 39, 0, 93, 27, 51, 81, 48, 80, 30, 69],
[54, 81, 74, 93, 0, 73, 43, 56, 104, 76, 76, 77],
[33, 8, 18, 27, 73, 0, 45, 61, 71, 88, 8, 63],
[57, 49, 60, 51, 43, 45, 0, 85, 88, 115, 52, 103],
[32, 64, 44, 81, 56, 61, 85, 0, 74, 43, 55, 23],
[89, 63, 71, 48, 104, 71, 88, 74, 0, 38, 69, 51],
[73, 84, 73, 80, 76, 88, 115, 43, 38, 0, 81, 28],
[29, 10, 11, 30, 76, 8, 52, 55, 69, 81, 0, 55],
[46, 61, 46, 69, 77, 63, 103, 23, 51, 28, 55, 0]]
pca = PCA(n_components=2)
coord = pca.fit_transform(distances[:n])
plt.scatter(coord[:,0], coord[:,1])
for i in coord:
x = np.where(coord == i)
plt.annotate((x[0][0]) ,i, color='red')
for j in order:
print(coord[j])
plt.plot(coord[:,0], coord[:,1], color='orange')
plt.show()


plt.plot(arr[:,0], arr[:,1])?