【发布时间】:2021-12-30 17:23:23
【问题描述】:
我有两个 xy 坐标列表,用于绘制两条曲线。我对曲线上方的区域感兴趣,所以我使用了 fill_between 来得出这个结论:
现在,我想要的是一种获取颜色区域未覆盖的坐标的方法,因此我可以绘制第三条曲线,就像我在下面的示例中使用 Paint 所做的红色曲线一样:
我尝试对列表进行排序,然后比较每一对以找到具有较低 y 值的列表,但这不起作用,因为每个列表可以有不同的大小和不同的 x 值。我还发现了一些关于叉积的线程,但这些线程使用的是直线,我无法理解如何将其推断到我的情况。
这是一个mwe:
import matplotlib.pyplot as plt
points_x = [1,3,5,7,9,11,13,15,17,19]
points_y = [10,8,7,6,3,5,3,9,7,6]
points_x2= [0,2,4,8,10,12,14,15,17,19,20,21,22]
points_y2 = [12,10,9,4,2,7,3,8,8,8,8,8,8]
plt.scatter(points_x, points_y, color="blue")
plt.scatter(points_x2, points_y2, color="green")
plt.fill_between(points_x, points_y, plt.ylim()[1], color='blue', alpha=0.5)
plt.fill_between(points_x2, points_y2, plt.ylim()[1], color='green', alpha=0.5)
#way to make a points_x3/points_y3 with only the coordinates at the edge of the
#overlapped areas
plt.show()
(我在想出正确的术语来定义我的问题时遇到了麻烦(非母语人士并且不习惯使用太多数学术语),因此对于可能提出重复问题的问题我深表歉意)
【问题讨论】:
-
您在 x=15 附近错过了一点吗?
-
@MadPhysicist 在第二个情节中?是的,我做到了,我的错。谢天谢地,我仍然得到了答案。
标签: python matplotlib plot curve