另外,您也可以使用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