【问题标题】:Plot and return points of Intersection between two curves plotted from dataframes从数据帧绘制的两条曲线之间的交点和返回点
【发布时间】:2021-06-10 13:40:56
【问题描述】:

我对编码有点陌生,目前正在尝试找出如何找出从数据帧中绘制的两条曲线的交点。

曲线是:

这是我现在的代码。

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()

然后我想在交叉点之前和之后删除橙色线的所有点。此分析的目的是计算橙色图下方但与蓝色图相交的点之间的面积:

.

在网上发现了一些类似的问题,但似乎没有任何效果(或者我做错了)。如果有人能指出我正确的方向,将不胜感激。谢谢!

【问题讨论】:

    标签: python pandas dataframe intersection curve


    【解决方案1】:

    您可以定义两条新曲线。一条将由两条曲线的逐点最小值给出,另一条将是一条为零的水平线。现在,您可以使用来自matplotlibfill_between 方法。这是一个例子:

    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)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-03-25
      • 1970-01-01
      • 1970-01-01
      • 2019-08-15
      • 2013-12-19
      • 2017-02-18
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多