【发布时间】:2017-12-06 23:21:06
【问题描述】:
我有两个列表,其中包含要使用 matplotlib 绘制的点的坐标:hx 和 hy,并且我有一个将这些点绘制为图像的函数:plotImage。
现在我想在这些点之间画一条线,但这条线应该以某种方式绕过图片。它不必完全通过图像的边界,重要的是它不会与图片重叠。
这是一个示例,绿线是我现在拥有的(它的凸包),红线是该线应该是什么样子的示例。
这是我的代码:
def plotImage(xData, yData, im):
for x, y in zip(xData, yData):
bb = Bbox.from_bounds(x,y,10,10)
bb2 = TransformedBbox(bb,ax.transData)
bbox_image = BboxImage(bb2,
norm = None,
origin=None,
clip_on=False)
bbox_image.set_data(im)
ax.add_artist(bbox_image)
fig=plt.figure()
ax=fig.add_subplot(111)
img = plt.imread('pic.png')
gx = list(map(lambda x: x - 5, hx)) # so the center of the picture is in the point I want to plot
gy = list(map(lambda y: y - 5, hy)) #(without this, the image is drawn so that the picture's left bottom corner is in my point)
plotImage(gx,gy,img)
plt.plot(hx, hy, 'g-', markersize=10)
所以我的问题是:如何计算这个红色的船体?
【问题讨论】:
-
红线一定要精确吗?它必须有和绿色一样多的顶点吗?
标签: python matplotlib convex-hull