0xb*_*00d 4 python visualization visual-studio
我是 Python 新手,想要执行一项相当简单的任务。我有一个二维点集,它作为二进制数据(即(x, y)坐标)存储在文件中,我想将其可视化。输出应如下图所示。
然而,我对这个主题的谷歌结果的数量感到不知所措。其中许多似乎用于三维点云可视化和/或大量数据点。因此,如果有人能为我的问题指出一个合适的解决方案,我将非常感激。
编辑:点集包含在格式如下的文件中:
0.000000000000000 0.000000000000000
1.000000000000000 1.000000000000000
1
0.020375738732779 0.026169010160356
0.050815740313746 0.023209931647163
0.072530406907906 0.023975230642589
Run Code Online (Sandbox Code Playgroud)
第一个数据向量是单个“1”下方行中的数据向量;IE (0.020375738732779, 0.026169010160356)。如何将其读入 python 中的向量?我可以使用打开该文件f = open("pointset file")
安装并导入 matplotlib 和 pyplot:
import matplotlib.pyplot as plt
Run Code Online (Sandbox Code Playgroud)
假设这是您的数据:
x = [1, 2, 5, 1, 5, 7, 8, 3, 2, 6]
y = [6, 7, 1, 2, 6, 2, 1, 6, 3, 1]
Run Code Online (Sandbox Code Playgroud)
如果需要,您可以使用推导式将坐标拆分为单独的列表:
x = [p[0] for p in points]
y = [p[1] for p in points]
Run Code Online (Sandbox Code Playgroud)
绘图很简单:
plt.scatter(x=x, y=y)
Run Code Online (Sandbox Code Playgroud)
结果:
许多定制都是可能的。
编辑:以下问题编辑
为了读取文件:
x = []
y = []
with open('pointset_file.txt', 'r') as f:
for line in f:
coords = line.split(' ')
x.append(float(coords[0]))
y.append(float(coords[1]))
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
389 次 |
| 最近记录: |