将对数曲线拟合到数据点并以numpy外推 [英] Fit a logarithmic curve to data points and extrapolate out in numpy
本文介绍了将对数曲线拟合到数据点并以numpy外推的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一组数据点(代码中的x和y)。我想绘制这些点,并为其拟合一条曲线,以显示使y = 100.0(y值为百分比)需要x的值。这是我尝试的方法,但是我的曲线是3级的多项式(我知道这是错误的)。对我来说,数据看起来是对数的,但是我现在知道如何对数据进行对数曲线的拟合。
I have a set of data points (x and y in the code). I would like to plot these points, and fit a curve to them that shows what value of x would be required to make y = 100.0 (y values are percentages). Here is what I have tried, but my curve is a polynomial of degree 3 (which I know is wrong). To me, the data looks logarithmic, but I do now know how to polyfit a logarithmic curve to my data.
import numpy as np
import matplotlib.pyplot as plt
x = np.array([4,8,15,29,58,116,231,462,924,1848])
y = np.array([1.05,2.11,3.95,7.37,13.88,25.46,43.03,64.28,81.97,87.43])
for x1, y1 in zip(x,y):
plt.plot(x1, y1, 'ro')
z = np.polyfit(x, y, 3)
f = np.poly1d(z)
for x1 in np.linspace(0, 1848, 110):
plt.plot(x1, f(x1), 'b+')
plt.show()
推荐答案
它看起来像是绑定曲线:
def binding(x,kd,bmax):
return (bmax*x)/(x+kd)
param=sp.optimize.curve_fit(binding, x,y)
plt.plot(x,y,'o',np.arange(2000),binding(np.arange(2000),*param[0]))
在这种情况下,严格来说,y = 100%仅会发生在x = inf
In which case, strictly speaking, y=100% will only happen at x=inf
这篇关于将对数曲线拟合到数据点并以numpy外推的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文