在txt文件中可视化坐标,Python

2024-10-02 00:39:13 发布

您现在位置:Python中文网/ 问答频道 /正文

我有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

这些数据随时间而变化。 我想画一张图,上面有三个集群和机器人质心坐标的路径。我想看看他们是如何随着时间而移动的

我知道我可以用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)

Tags: inforlinerobotfirstvaluesclusterprint

热门问题