散点图线到无序数据

2024-05-17 21:38:29 发布

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

我在跟踪一只鸟类的活动。我在xy图上有检测点。我想将上一个检测点连接到下一个检测点,而不考虑方向。这将有助于消除无关检测

数据样本:

Sample input 目标是从上一个数据点到下一个数据点有一条直线

Sample output

方法1失败:

plt.figure('Frame',figsize=(16,12))
plt.imshow(frame)
plt.plot(x, y, '-ro', 'd',markersize=2.5, color='orange')

Method 1 output

方法2失败:

plt.plot(np.sort(x), y[np.argsort(x)], '-bo', ms = 2)

Method 2 output


Tags: 数据sample方法目标inputoutputplot鸟类
1条回答
网友
1楼 · 发布于 2024-05-17 21:38:29

我使用了您的样本数据,并用方法1(但使用熊猫)绘制了一个图,结果与您预期的一样。我不明白你为什么会有不成功的结果

data = [{'frame': 1, 'x': 5, 'y': 15},
 {'frame': 4, 'x': 10, 'y': 15},
 {'frame': 5, 'x': 15, 'y': 15},
 {'frame': 6, 'x': 20, 'y': 15},
 {'frame': 7, 'x': 23, 'y': 20},
 {'frame': 8, 'x': 25, 'y': 25},
 {'frame': 11, 'x': 20, 'y': 23},
 {'frame': 15, 'x': 15, 'y': 20},
 {'frame': 18, 'x': 8, 'y': 18},
 {'frame': 19, 'x': 8, 'y': 10},
 {'frame': 20, 'x': 12, 'y': 7}]
df = pd.DataFrame(data).sort_values('frame')
df.plot(x='x', y='y')

enter image description here

相关问题 更多 >