我想知道是否有人能给我一个找到两个等值线图交点的线索?理想情况下,它会采用一对轮廓,然后返回交叉点的坐标
Z1 = somefunction
Z2 = somefunction1
Z3 = somefunction2
xlist = np.linspace(0, 10, 50)
ylist = np.linspace(0, 10, 50)
X, Y = np.meshgrid(xlist, ylist)
figtest = plt.figure()
axtest = figtest.add_subplot( 111 )
axtest.contour(X,Y,Z1,[1],colors='green', linewidths=4)
axtest.contour(X,Y,Z2,[1],colors='orange', linewidths=4)
axtest.contour(X,Y,Z3,[1],colors='blue',linewidths=4)
axtest.set_xlim([0, 9])
axtest.set_ylim([0, 9])
axtest.legend()
axtest.grid()
plt.show()
到目前为止,我试过,提取构成轮廓的坐标并尝试找到两个轮廓的数组的交集,但它返回一个空数组,我假设因为没有一个精确的坐标,两个数组的成员
编辑:
我做到了。以下是:
from shapely import geometry
def findIntersection(contour1,contour2):
p1 = contour1.collections[0].get_paths()[0]
v1 = p1.vertices
p2 = contour2.collections[0].get_paths()[0]
v2 = p2.vertices
poly1 = geometry.LineString(v1)
poly2 = geometry.LineString(v2)
intersection = poly1.intersection(poly2)
return intersection
c1 = axtest.contour(X,Y,Z1,[1],colors='green', linewidths=4)
c2 = axtest.contour(X,Y,Z2,[1],colors='orange', linewidths=4)
intersection_example = findIntersection(c1,c2)
其中坐标可以通过
访问intersection_example.x ##get x points
intersection_example.y ##get y points
list(intersection_example.coords) ## get in [x,y] formatting
希望它可以帮助某人