x = [-5,-4.19,-3.54,-3.31,-2.56,-2.31,-1.66,-0.96,-0.22,0.62,1.21]
y = [0.01,0.01,0.03,0.04,0.07,0.09,0.16,0.28,0.45,0.65,0.77]
plt.scatter(x, y)
new = np.linspace(-6, 2)
line, = plt.plot(new, inter(new, x, y))
xdata = line.get_xdata()
ydata = line.get_ydata()
print("X-datas: {}\n Y-datas: {}".format(xdata, ydata))
plt.show()
X 資料:[-6。-5.83673469 -5.67346939 -5.51020408 -5.34693878 -5.18367347 -5.02040816 -4.85714286 -4.69387755 -4.53061224 -4.36734694 -4.20408163 -4.04081633 -3.87755102 -3.71428571 -3.55102041 -3.3877551 -3.2244898 -3.06122449 -2.89795918 -2.73469388 -2.57142857 -2.40816327 -2.24489796 -2.08163265 -1.91836735 -1.75510204 -1.59183673 -1.42857143 -1.26530612 -1.10204082 -0.93877551 -0.7755102 -0.6122449 -0.44897959 -0.28571429 -0.12244898 0.04081633 0.20408163 0.36734694 0.53061224 0.69387755 0.85714286 1.02040816 1.18367347 1.34693878 1.51020408 1.67346939 1.83673469 2]
Y型DATAS:-0.01204394 -0.00302114 0.00328497 0.00731081 0.00949282 0.01026743 0.01007108 0.0093402 0.00851122 0.00802059 0.00830473 0.00980007 0.01270645 0.01709244 0.02276363 0.02951097 0.03669359 0.04295611 0.04814326 0.0535818 0.06028353 0.06926028 0.08176299 0.09625576 0.11210497 0.12895267 0.14776008 0.16925751 0.19376669 0.22132663 0.25163393 0.28441688 0.31953663 0.35641761 0.39468924 0.43398094 0.47401019 0.51426535 0.55412183 0.59301685 0.63038764 0.66578449 0.69938197 0.73201447 0.7646666 0.79832295 0.83396812 0.87258672 0.91516335 0.96268261]

inter是插入資料的函式,我得到輸出的陣列。
如何從擬合曲線中獲得特定值。假設 X = -2.31 那么我想從擬合曲線中獲得 Y 值。
uj5u.com熱心網友回復:
您將獲得最接近x = -2.31使用點的索引numpy.searchsorted。
n = np.searchsorted(xdata, -2.31)
y = ydata[n]
請記住,要使其正常作業,您需要xdata進行排序,并且由于兩個索引之間的 dx,結果會略有偏差。您的資料擁有的點越多,您就越能將這種不準確性降低到無關緊要的程度。
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/438524.html
標籤:Python matplotlib
上一篇:僅針對一列中的一個特定值繪制圖形
