Convex Hull Python Python中的一些问题

问题描述 投票:0回答:1

我正在尝试在python中将一些随机点凸包化,我得到了这个;

from scipy.spatial import ConvexHull
import matplotlib.pyplot as plt
import numpy as np

points = np.random.rand(15,2)   #Random points in 2-D

hull = ConvexHull(points)

plt.plot(points[:,0], points[:,1], 'o',color='k')

for simplex in hull.simplices:
    plt.plot(points[simplex, 0], points[simplex, 1], 'c')

plt.plot(points[hull.vertices,0], points[hull.vertices,1], 'c', lw=-1)
plt.plot(points[hull.vertices[0],0], points[hull.vertices[0],1], 'c-')
plt.show()
  • 但是我必须首先更改X,Y标签和点数限制在0到9之间。例如(0,1,2,3,4,5,6,7,8,9)
  • 第二个是,我必须用一个圆标记这个凸点。As in example
python matplotlib scipy convex-hull
1个回答
0
投票

np.rand()替换randint(0, 10)将生成从0,1,...9的整数形式的坐标。

使用'。'因为标记将导致给定点的标记变小。

使用'o'作为标记,将markeredgecolor设置为markerfacecolor并将其设置为'none'将得到圆形标记。

from scipy.spatial import ConvexHull
import matplotlib.pyplot as plt
import numpy as np

points = np.random.randint(0, 10, size=(15,2))   #Random points in 2-D

hull = ConvexHull(points)

plt.plot(points[:,0], points[:,1], '.',color='k')

for simplex in hull.simplices:
    plt.plot(points[simplex, 0], points[simplex, 1], 'c')

plt.plot(points[hull.vertices,0], points[hull.vertices,1], 'o', mec='r', color='none', lw=1)
plt.show()
© www.soinside.com 2019 - 2024. All rights reserved.