Python - 仅绘制数据集的最外层点

标签 python matplotlib plot

我有一组随机点排列成方形(边缘粗糙),我想只绘制最外面的点 - 只绘制最接近形状假想边缘的点(这样我就可以在有一些重叠的多个相似数据集之间有清晰的边界)。

非常感谢任何关于如何选择这些点的建议。

最佳答案

您可以使用 scipy 的凸包函数,参见 scipy docs . 文档页面给出了以下示例

from scipy.spatial import ConvexHull
points = np.random.rand(30, 2)   # 30 random points in 2-D
hull = ConvexHull(points)

import matplotlib.pyplot as plt
plt.plot(points[:,0], points[:,1], 'o')
# plot convex hull polygon
plt.plot(points[hull.vertices,0], points[hull.vertices,1], 'r--', lw=2)
# plot convex full vertices
plt.plot(points[hull.vertices[0],0], points[hull.vertices[0],1], 'ro')
plt.show()

关于Python - 仅绘制数据集的最外层点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25787637/

相关文章:

python - 为什么 powershell 和 python 对同一命令给出不同的结果?

python - 在文本文件中的两个单词之间查找/替换字符串

matlab - 使用 ==> plot3 时出错 无法从单元格转换为 double 。 plot3(p(1, :), p(2, :), p(3,:) ,'+r' );

plot - Julia 与原子的现场情节

python - 使用 pandas 的绘图方法在 1 行中绘制图表时出现问题

python - 无法使用 collidepoint(event.pos) 移动图像?

python-2.7 - 无法将图形另存为 .eps [无法识别 gswin32c]

python - Python 中的 plt.contour

python - Matplotlib zorder ax 隐藏其他轴的线

python - 如果发生这种情况,我该如何安装 PIL?