Python - 按顺序连接两组点

Python - connect two sets of dots in order

我创建了两个散点图并将它们放在同一个图表上。我也想匹配两个散点图的点数(注意两个散点图的点数相同)

下面提供了我目前的代码,我想要得到的情节在这个post的底部勾勒出来。

plt.scatter(tmp_df['right_eye_x'], tmp_df['right_eye_y'],
            color='green', label='right eye')
plt.scatter(tmp_df['left_eye_x'], tmp_df['left_eye_y'],
            color='cyan', label='left eye')
plt.legend()

这是您可以使用的假数据框,以防您需要进行一些测试。 (我的数据是以下格式;你可以使用代码块中的最后两行来创建数据框)

timestamp right_eye_x  right_eye_y left_eye_x  left_eye_y
    15        54           22          28          19
    20        56           21          29          21
    25        59           16          28          16   
    30        58           18          31          18   
    35        62           15          33          14


data = {'timestamp':[15,20,25,30,35],
'right_eye_x':[54, 56, 59, 58, 62],
'right_eye_y':[22, 21, 16, 18, 15],
'left_eye_x':[28, 29, 22, 31, 33],
'left_eye_y':[19, 21, 16, 18, 14]}
tmp_df = pd.DataFrame(data)

我看到了这个post:Matplotlib python connect two scatter plots with lines for each pair of (x,y) values? 虽然我还是很迷茫。

如有任何见解,我将不胜感激!谢谢! (如果您发现任何部分令人困惑,请告诉我!)

使用您引用的 post 中显示的评论中的解决方案。

import matplotlib.pyplot as plt
import numpy as np
x1 = [0.19, 0.15, 0.13, 0.25]
x2 = [0.18, 0.5, 0.13, 0.25]
y1 = [0.1, 0.15, 0.3, 0.2]
y2 = [0.85, 0.76, 0.8, 0.9]

for i in range(len(x1)):     
  plt.plot([x1[i],x2[i]], [y1[i],y2[i]])

你可以把标签、颜色和东西看 https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.plot.html