Python 如何提取matplotlib路径顶点中包含的数据点?

Python 如何提取matplotlib路径顶点中包含的数据点?,python,matplotlib,path,vertices,Python,Matplotlib,Path,Vertices,我定义多边形的顶点及其类型如下: verts=[(x1,y1),(x2,y2),(x3,y3),(x4,y4),(0,0)] codes=[Path.MOVETO,Path.LINETO,Path.LINETO,Path.LINETO,Path.CLOSEPOLY] path=Path(verts,codes) patch=patches.PathPatch(path) ax.plot(x_data[inds], y_data[inds]) 现在,我想提取包含在顶点内的数据点的索引,以便对它

我定义多边形的顶点及其类型如下:

verts=[(x1,y1),(x2,y2),(x3,y3),(x4,y4),(0,0)]
codes=[Path.MOVETO,Path.LINETO,Path.LINETO,Path.LINETO,Path.CLOSEPOLY]
path=Path(verts,codes)
patch=patches.PathPatch(path)
ax.plot(x_data[inds], y_data[inds])
现在,我想提取包含在顶点内的数据点的索引,以便对它们进行操作。我尝试了以下方法:

datapts = np.column_stack((x_data,y_data))
inds, = Path(verts).contains_points(datapts)

当然,顶点本身不是数据,所以这不起作用。感谢您的帮助。

在我发布上述内容3分钟后,我找到了答案:

inds = path.contains_points(datapts)
这可以按如下方式使用:

verts=[(x1,y1),(x2,y2),(x3,y3),(x4,y4),(0,0)]
codes=[Path.MOVETO,Path.LINETO,Path.LINETO,Path.LINETO,Path.CLOSEPOLY]
path=Path(verts,codes)
patch=patches.PathPatch(path)
ax.plot(x_data[inds], y_data[inds])