I have a data of x and y that I want to construct a polygon representing this data. To do that I should sort the points in a way that lines representing the polygon are drawn correctly. How can I do that in python? I think there should be a double constrain or something, one for the angle and the other is for the distance maybe. Any ideas?!
The data is in here: Data
what I want is something like this:

I have tried the following code but the result is incorrect:
mean = np.mean(data, axis=0)
# Compute angles
angles = np.arctan2((data-mean)[:, 1], (data-mean)[:, 0])
# Transform angles from [-pi,pi] -> [0, 2*pi]
angles[angles < 0] = angles[angles < 0] + 2 * np.pi
# Sort
sorting_indices = np.argsort(angles)
sorted_data = data[sorting_indices]
