【问题标题】:Get Tangent Point of a Curve获取曲线的切点
【发布时间】:2022-01-13 01:22:10
【问题描述】:

我有以下 df(我将在帖子中附上):

然后我绘制两列,称为价格和称为 OG。它显示了这样的内容:

plt.plot(out["PRICE"], out["OG [%]"])

所以我想得到优化曲线的切点(x,y)。在图像中我可以看到它在附近 (80, 0.160),但是考虑到曲线将来可能会发生变化,我怎样才能自动获得这个坐标?

提前致谢!

CSV 格式的 DF:

,INCREASE [%],PRICE,INCREASE,QTY,GPS,NNS,OG [%] 
0,0.0,47.69,0.0,239032932.10219583,11399480531.953718,9649069936.361042
1,0.1,52.458999999999996,4.769,267545911.79200616,14035190986.69685,11961949944.986732,0.27315694384293565 
2,0.2,57.227999999999994,9.538,296058891.48181653,16942858241.721395,14546786753.89384,0.24307636032561325 
3,0.30000000000000004,61.997,14.307000000000002,324571871.1716268,20122482297.027348,17403580363.082355,0.21857913428577896 
4,0.4,66.76599999999999,19.076,353084850.8614371,23574063152.614704,20532330772.55227,0.198325906714522 
5,0.5,71.535,23.845,381597830.5512475,27297600808.483486,23933037982.30361,0.18134997420002735 
6,0.6000000000000001,76.304,28.614000000000004,410110810.2410579,31293095264.633682,27605701992.33637,0.16694472549220507 
7,0.7000000000000001,81.07300000000001,33.383,438623789.93086815,35560546521.06528,31550322802.650528,0.1545858626459231 
8,0.8,85.842,38.152,467136769.6206784,40099954577.778275,35766900413.246086,0.14387833953735796 
9,0.9,90.61099999999999,42.921,495649749.3104888,44911319434.7727,40255434824.12307,0.13452003951711053 
10,1.0,95.38,47.69,524162729.0002991,49994641092.04852,45015926035.28145,0.12627665505254082 
11,1.1,100.149,52.459,552675708.6901095,55349919549.605774,50048374046.72126,0.11896408514089048 
12,1.2000000000000002,104.918,57.22800000000001,581188688.3799199,60977154807.444435,55352778858.44248,0.11243592554246645 
13,1.3,109.687,61.997,609701668.0697302,66876346865.56449,60929140470.44511,0.10657445172186328 
14,1.4000000000000001,114.456,66.766,638214647.7595404,73047495723.96596,66777458882.729126,0.10128402946033532 
15,1.5,119.225,71.535,666727627.4493507,79490601382.64883,72897734095.29456,0.09648623602161768 
16,1.6,123.994,76.304,695240607.1391611,86205663841.61314,79289966108.14143,0.09211620281895366 
17,1.7000000000000002,128.763,81.07300000000001,723753586.8289715,93192683100.85886,85954154921.26971,0.08811984166718287 
18,1.8,133.53199999999998,85.842,752266566.5187817,100451659160.38594,92890300534.67935,0.08445171808362244 
19,1.9000000000000001,138.301,90.611,780779546.208592,107982592020.19447,100098402948.37045,0.08107340396640193 
20,2.0,143.07,95.38,809292525.8984023,115785481680.28442,107578462162.34296,0.07795218934826136

【问题讨论】:

  • “优化曲线的切点(x,y)”是什么意思?
  • 曲线的拐点或拐点。我在 P(80, 0.160) 中看到的坐标

标签: python-3.x pandas matplotlib


【解决方案1】:

这条特殊的曲线没有拐点或“拐点”(肘):

from kneed import KneeLocator
kn = KneeLocator(x = out['PRICE'], y = out['OG [%] '], curve='convex', direction='decreasing')
print(kn.knee)
None

但如果是这样,你会这样做:

y = [7342, 6881, 6531,  
6356, 6209, 6094, 
5980, 5880, 5779, 
5691, 5617, 5532, 
5467, 5395, 5345, 
5290, 5243, 5207, 
5164]

x = range(1, len(y)+1)

import kneed
from kneed import KneeLocator
kn = KneeLocator(x, y, curve='convex', direction='decreasing')
print(kn.knee)
print(round(kn.knee_y, 3))


import matplotlib.pyplot as plt
plt.xlabel('x')
plt.ylabel('y')
plt.plot(x, y, 'bx-')
plt.vlines(kn.knee, plt.ylim()[0], plt.ylim()[1], linestyles='dashed')

在哪里

(print(kn.knee),print(round(kn.knee_y, 3)))
(5,6209)

为您提供膝盖的坐标。

【讨论】:

    猜你喜欢
    • 2015-06-20
    • 2021-06-24
    • 1970-01-01
    • 2011-05-04
    • 1970-01-01
    • 2020-05-31
    • 1970-01-01
    • 1970-01-01
    • 2017-07-12
    相关资源
    最近更新 更多