I have four coordinates in my
Based on this data, I try to connect the points in such a way that a parallelogram is created.
# selecting columns start with 'lat' xx = df[[col for col in test if col.startswith('lat')]].stack().to_list() # selecting columns start with 'lon' yy = df[[col for col in test if col.startswith('lon')]].stack().to_list() plt.scatter(xx,yy)
Unfortunatelly, when I try to connect points with lines, it doesn’t work:
I guess it’s because the points are not ordered. I also tried this:
points = np.c_[xx, yy] from sklearn.neighbors import NearestNeighbors clf = NearestNeighbors(2).fit(points) G = clf.kneighbors_graph() import networkx as nx T = nx.from_scipy_sparse_matrix(G) order = list(nx.dfs_preorder_nodes(T, 0)) xx = xx[order] yy = yy[order] plt.plot(xx, yy) plt.show()
But it is still incorrect.
Do you have idea where is the issue?
You can calculate the convex hull of the four points:
import numpy as np points=np.column_stack((xx,yy)) from scipy.spatial import ConvexHull hull = ConvexHull(points) for simplex in hull.simplices: plt.plot(points[simplex, 0], points[simplex, 1], 'k-')