I have txt file. Every line has 11 elements. Below is shown the file.
4.05010767925,2.33864731895,2.41543839929,3.86018471931,0.481566107186,4.85262264971,3.83877010346,-0.89860066431,1.97925697639,4.21318223617,2.30219401586
3.89719519419,1.77275873336,4.09475833016,4.27680399518,1.69581119081,1.18793974114,3.68362710809,-0.98641367602,3.03549428068,4.22379105922,2.08934242323
3.89242070493,1.76728285022,4.09475941492,4.27969152155,1.70314776061,1.18794072811,3.67846761288,-0.985884313575,3.0354946827,4.23387954002,1.90488012639
It represents the coordinates of centroids of three clusters.
X_cluster1,Y_cluster1,Z_cluster1, X_cluster2, Y_cluster2, Z_cluster2, X_cluster3, Y_cluster3, Z_cluster3, X_robot, Y_robot
These data are changing with time. I wish to plot a graph which will have the paths of the coordinates of centroids of the three clusters and the robot as well. I want to see how they all moved with time.
I know I can plot it with plt.scatter(), But I can't somehow save the coordinates in variables. Sorry I am new to Python and not sure how to proceed.
f = open('centroids_paths.txt', 'r').readlines() #f.close() x_values_first_cluster = [] x_values_second_cluster =[] x_values_third_cluster = [] y_values_first_cluster = [] y_values_second_cluster = [] y_values_third_cluster = [] x_robot = [] y_robot = [] # Y and Z are the same like above for line in f: tmp = line.strip().split(",") values = [float(v) for v in tmp] points4d = np.array(values).reshape(-1,11) #11 is number of elements in the line print("points4d", points4d) for i in points4d: points3d_first_cluster = points4d[:, :3] # HARD CODED PART points3d_second_cluster = points4d[:, 3:6] points3d_third_cluster = points4d[:, 6:9] #print("x_values_first_cluster",x_values_first_cluster) print("points3d first cluster ",points3d_first_cluster) # print("points3d second cluster", points3d_second_cluster) # print("points for third cluster", points3d_third_cluster)