另外,您也可以使用curve_fit
这可能会派上用场,如果你有比只有两个数据点多。输出看起来是这样的:
正如你可以看到,图中包含了所需的数据点。我使用了@ lanery的功能来配合;你当然可以选择你喜欢的任何功能。这是一些内嵌评论的代码:
import numpy as np
import matplotlib.pyplot as plt
from scipy.optimize import curve_fit
def sigmoid(x, a, b, c, d):
return ((a - b)/(1. + np.exp(x - (c/2)) ** d)) + b
# one needs at least as many data points as parameters, so I just duplicate the data
xdata = [0., 48.] * 2
ydata = [8., 2.] * 2
# plot data
plt.plot(xdata, ydata, 'bo', label='data')
# fit the data
popt, pcov = curve_fit(sigmoid, xdata, ydata, p0=[1., 1., 50., 0.5])
# plot the result
xdata_new = np.linspace(0, 50, 100)
plt.plot(xdata_new, sigmoid(xdata_new, *popt), 'r-', label='fit')
plt.legend(loc='best')
plt.show()
'atan'和'atanh'是流行的sigmoid函数 – f5r5e5d