Визуализировать координаты в txt файле, Python - PullRequest
2 голосов
/ 05 августа 2020

У меня есть txt файл. В каждой строке 11 элементов. Ниже показан файл.

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

Он представляет собой координаты центроидов трех кластеров.

X_cluster1,Y_cluster1,Z_cluster1, X_cluster2, Y_cluster2, Z_cluster2, X_cluster3, Y_cluster3, Z_cluster3, X_robot, Y_robot

Эти данные меняются со временем. Я хочу sh построить график, который будет иметь пути координат центроидов трех кластеров, а также робота. Я хочу увидеть, как они все двигались со временем.

Я знаю, что могу построить это с помощью plt.scatter () , но я не могу как-то сохранить координаты в переменных. Извините, я новичок в Python и не знаю, как действовать.

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)
...