简体   繁体   English

Plot 和从数据帧绘制的两条曲线之间的交点的返回点

[英]Plot and return points of Intersection between two curves plotted from dataframes

I am kind of new to coding and am currently trying to figure out how to find out the point of intersection of two curves plotted from dataframes.我对编码有点陌生,目前正在尝试找出如何找出从数据帧绘制的两条曲线的交点。

The curves are:曲线是:

这里

This is the code I have right now.这是我现在拥有的代码。

GZ_positive = data.loc[data["GZ"] >= 0] 

x_new = GZ_positive['heel']
y_new = GZ_positive['GZ']


wind_heeling = pd.read_csv('wind_heeling.csv')  

GZ_positive['GZ'] = GZ_positive['GZ']/13400
wind_heeling['GZ_wind'] = wind_heeling['GZ_wind']/13400

x_wind = wind_heeling['Heel']
y_wind = wind_heeling['GZ_wind']

plt.figure()
plt.plot(x_new,y_new)
plt.plot(x_wind,y_wind)
plt.grid(True)
plt.show()

I would then like to drop all the points of the orange line before and after the points of intersection.然后我想在交叉点之前和之后删除橙色线的所有点。 The aim of this analysis is to calculate the area under the orange graph but between the points where it intersects the blue graph:此分析的目的是计算橙色图下方但与蓝色图相交的点之间的面积:

这里 . .

Have found a few similar problems online but nothing seems to work (or I have done it wrong).在网上发现了一些类似的问题,但似乎没有任何效果(或者我做错了)。 Would appreciate it if anyone could point me in the right direction.如果有人能指出我正确的方向,将不胜感激。 Thanks!谢谢!

You can define two new curves.您可以定义两条新曲线。 One will be given by the pointwise minimum of your two curves, the other will be a horizontal line at zero.一条将由两条曲线的逐点最小值给出,另一条将是一条为零的水平线。 Now, you can use the fill_between method from matplotlib .现在,您可以使用matplotlib中的fill_between方法。 Here is an example:这是一个例子:

xs = np.linspace(0, 10, 100)
ys = -xs**2 - 4 + 10*xs

df = pd.DataFrame({
    "one": 5,
    "two": ys,
})

ax = df.plot()
ax.set_ylim(0, 30)

upper = df.min(1)
lower = np.zeros(df.shape[0])

ax.fill_between(df.index, lower, upper)

在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM