Python曲线拟合(polyfit , curve_fit, interp1d插值)
在python中,Numpy.polyfit()是一个在多项式函数内拟合数据的方法。当最小二乘法的拟合条件很差时,polyfit会发出RankWarning。curve_fit () 自定义函数拟合前两种都限于你得提前知道待拟合的是什么函数, 可不可以通过大量的点插值得到函数呢?python的scipy.interpolate模块有一维插值函数interp1d,二维插值函数interp2d,多维插
np.polyfit 多项式拟合
在python中,Numpy.polyfit()是一个在多项式函数内拟合数据的方法。当最小二乘法的拟合条件很差时,polyfit会发出RankWarning。
对散点进行多项式拟合并打印出拟合函数以及拟合后的图形程序如下
例1
在这个程序中,首先,导入matplotlib和numpy库。设置x、y、p和t的值。然后,使用这个x、y、p和t的值,通过拟合绘制多项式。
import numpy as np
import matplotlib.pyplot as plt
np.random.seed(46)
x = np.linspace(0, 1, 25)
y = np.cos(x) + 0.3 * np.random.rand(25)
p = np.poly1d(np.polyfit(x, y, 4))
t = np.linspace(0, 1, 250)
plt.plot(x, y, 'o', t, p(t), '-')
plt.show()
例2
在这个程序中,也是如此,首先,导入matplotlib和numpy库。设置x和y的值。然后,计算多项式并设置x和y的新值。一旦完成,使用函数polyfit()拟合多项式。
import numpy as np
import matplotlib.pyplot as plt
np.random.seed(12)
x = np.linspace(-20, 20, 10)
y = 3.6 * pow(x, 3) + 8.3 * pow(x, 2) + 5.1 * pow(x, 1) + 5
func = np.polyfit(x, y, 4)
xn = np.linspace(-20, 20, 1000)
yn = np.poly1d(func)
plt.plot(xn, yn(xn), x, y, 'o')
plt.show()
curve_fit () 自定义函数拟合
能拟合的函数不止下面这些,只要你写出想要使用的函数的表达式,就可以得到函数的参数!!!
import numpy as np # NumPy https://numpy.org/
import matplotlib.pyplot as plt # Matplotlib https://matplotlib.org/
from scipy.optimize import curve_fit # https://www.scipy.org/
# 三次 - 跟前面所说的poly_fit一个意思
def func_poly_3(x, a, b, c , d):
return a*x*x*x + b*x*x + c*x + d
# 幂函数
def func_power(x, a, b):
return x**a + b
# 指数函数
def func_exp(x, a, b):
return a**x + b
def Hyperb(x, a1, a2, qi):
y = qi / np.power(1 + a1 * a2 * x, 1 / a2)
return y
xdata=[1.0, 1.0185728, 1.0371457, 1.0557185, 1.0742913, 1.0928641, 1.111437, 1.1300098, 1.1485826, 1.1671554, 1.1857283, 1.2043011, 1.2228739, 1.2414467, 1.2600196, 1.2785924, 1.2971652, 1.315738, 1.3343109, 1.3528837, 1.3714565, 1.3900293, 1.4086022, 1.427175, 1.4457478, 1.4643206, 1.4828935, 1.5014663, 1.5200391, 1.5386119, 1.5571848, 1.5757576, 1.5943304, 1.6129032, 1.6314761, 1.6500489, 1.6686217, 1.6871945, 1.7057674, 1.7243402, 1.742913, 1.7614858, 1.7800587, 1.7986315, 1.8172043, 1.8357771, 1.85435, 1.8729228, 1.8914956, 1.9100684, 1.9286413, 1.9472141, 1.9657869, 1.9843597, 2.0029326, 2.0215054, 2.0400782, 2.058651, 2.0772239, 2.0957967, 2.1143695, 2.1329423, 2.1515152, 2.170088, 2.1886608, 2.2072336, 2.2258065, 2.2443793, 2.2629521, 2.2815249, 2.3000978, 2.3186706, 2.3372434, 2.3558162, 2.3743891, 2.3929619, 2.4115347, 2.4301075, 2.4486804, 2.4672532, 2.485826, 2.5043988, 2.5229717, 2.5415445, 2.5601173, 2.5786901, 2.597263, 2.6158358, 2.6344086, 2.6529814, 2.6715543, 2.6901271, 2.7086999, 2.7272727, 2.7458456, 2.7644184, 2.7829912, 2.801564, 2.8201369, 2.8387097, 2.8572825, 2.8758553, 2.8944282, 2.913001, 2.9315738, 2.9501466, 2.9687195, 2.9872923, 3.0058651, 3.0244379, 3.0430108, 3.0615836, 3.0801564, 3.0987292, 3.1173021, 3.1358749, 3.1544477, 3.1730205, 3.1915934, 3.2101662, 3.228739, 3.2473118, 3.2658847, 3.2844575, 3.3030303, 3.3216031, 3.340176, 3.3587488, 3.3773216, 3.3958944, 3.4144673, 3.4330401, 3.4516129, 3.4701857, 3.4887586, 3.5073314, 3.5259042, 3.544477, 3.5630499, 3.5816227, 3.6001955, 3.6187683, 3.6373412, 3.655914, 3.6744868, 3.6930596, 3.7116325, 3.7302053, 3.7487781, 3.7673509, 3.7859238, 3.8044966, 3.8230694, 3.8416422, 3.8602151, 3.8787879, 3.8973607, 3.9159335, 3.9345064, 3.9530792, 3.971652, 3.9902248, 4.0087977, 4.0273705, 4.0459433, 4.0645161, 4.083089, 4.1016618, 4.1202346, 4.1388074, 4.1573803, 4.1759531, 4.1945259, 4.2130987, 4.2316716, 4.2502444, 4.2688172, 4.28739, 4.3059629, 4.3245357, 4.3431085, 4.3616813, 4.3802542, 4.398827, 4.4173998, 4.4359726, 4.4545455, 4.4731183, 4.4916911, 4.5102639, 4.5288368, 4.5474096, 4.5659824, 4.5845552, 4.6031281, 4.6217009, 4.6402737, 4.6588465, 4.6774194, 4.6959922, 4.714565, 4.7331378, 4.7517107, 4.7702835, 4.7888563, 4.8074291, 4.826002, 4.8445748, 4.8631476, 4.8817204, 4.9002933, 4.9188661, 4.9374389, 4.9560117, 4.9745846, 4.9931574, 5.0117302, 5.030303, 5.0488759, 5.0674487, 5.0860215, 5.1045943, 5.1231672, 5.14174, 5.1603128, 5.1788856, 5.1974585, 5.2160313, 5.2346041, 5.2531769, 5.2717498, 5.2903226, 5.3088954, 5.3274682, 5.3460411, 5.3646139, 5.3831867, 5.4017595, 5.4203324, 5.4389052, 5.457478, 5.4760508, 5.4946237, 5.5131965, 5.5317693, 5.5503421, 5.568915, 5.5874878, 5.6060606, 5.6246334, 5.6432063, 5.6617791, 5.6803519, 5.6989247, 5.7174976, 5.7360704, 5.7546432, 5.773216, 5.7917889, 5.8103617, 5.8289345, 5.8475073, 5.8660802, 5.884653, 5.9032258, 5.9217986, 5.9403715, 5.9589443, 5.9775171, 5.9960899, 6.0146628, 6.0332356, 6.0518084, 6.0703812, 6.0889541, 6.1075269, 6.1260997, 6.1446725, 6.1632454, 6.1818182, 6.200391, 6.2189638, 6.2375367, 6.2561095, 6.2746823, 6.2932551, 6.311828, 6.3304008, 6.3489736, 6.3675464, 6.3861193, 6.4046921, 6.4232649, 6.4418377, 6.4604106, 6.4789834, 6.4975562, 6.516129, 6.5347019, 6.5532747, 6.5718475, 6.5904203, 6.6089932, 6.627566, 6.6461388, 6.6647116, 6.6832845, 6.7018573, 6.7204301, 6.7390029, 6.7575758, 6.7761486, 6.7947214, 6.8132942, 6.8318671, 6.8504399, 6.8690127, 6.8875855, 6.9061584, 6.9247312, 6.943304, 6.9618768, 6.9804497, 6.9990225, 7.0175953, 7.0361681, 7.054741, 7.0733138, 7.0918866, 7.1104594, 7.1290323, 7.1476051, 7.1661779, 7.1847507, 7.2033236, 7.2218964, 7.2404692, 7.259042, 7.2776149, 7.2961877, 7.3147605, 7.3333333, 7.3519062, 7.370479, 7.3890518, 7.4076246, 7.4261975, 7.4447703, 7.4633431, 7.4819159, 7.5004888, 7.5190616, 7.5376344, 7.5562072, 7.5747801, 7.5933529, 7.6119257, 7.6304985, 7.6490714, 7.6676442, 7.686217, 7.7047898, 7.7233627, 7.7419355, 7.7605083, 7.7790811, 7.797654, 7.8162268, 7.8347996, 7.8533724, 7.8719453, 7.8905181, 7.9090909, 7.9276637, 7.9462366, 7.9648094, 7.9833822, 8.001955, 8.0205279, 8.0391007, 8.0576735, 8.0762463, 8.0948192, 8.113392, 8.1319648, 8.1505376, 8.1691105, 8.1876833, 8.2062561, 8.2248289, 8.2434018, 8.2619746, 8.2805474, 8.2991202, 8.3176931, 8.3362659, 8.3548387, 8.3734115, 8.3919844, 8.4105572, 8.42913, 8.4477028, 8.4662757, 8.4848485, 8.5034213, 8.5219941, 8.540567, 8.5591398, 8.5777126, 8.5962854, 8.6148583, 8.6334311, 8.6520039, 8.6705767, 8.6891496, 8.7077224, 8.7262952, 8.744868, 8.7634409, 8.7820137, 8.8005865, 8.8191593, 8.8377322, 8.856305, 8.8748778, 8.8934506, 8.9120235, 8.9305963, 8.9491691, 8.9677419, 8.9863148, 9.0048876, 9.0234604, 9.0420332, 9.0606061, 9.0791789, 9.0977517, 9.1163245, 9.1348974, 9.1534702, 9.172043, 9.1906158, 9.2091887, 9.2277615, 9.2463343, 9.2649071, 9.28348, 9.3020528, 9.3206256, 9.3391984, 9.3577713, 9.3763441, 9.3949169, 9.4134897, 9.4320626, 9.4506354, 9.4692082, 9.487781, 9.5063539, 9.5249267, 9.5434995, 9.5620723, 9.5806452, 9.599218, 9.6177908, 9.6363636, 9.6549365, 9.6735093, 9.6920821, 9.7106549, 9.7292278, 9.7478006, 9.7663734, 9.7849462, 9.8035191, 9.8220919, 9.8406647, 9.8592375, 9.8778104, 9.8963832, 9.914956, 9.9335288, 9.9521017, 9.9706745, 9.9892473, 10.00782, 10.026393, 10.044966, 10.063539, 10.082111, 10.100684, 10.119257, 10.13783, 10.156403, 10.174976, 10.193548, 10.212121, 10.230694, 10.249267, 10.26784, 10.286413, 10.304985, 10.323558, 10.342131, 10.360704, 10.379277, 10.397849, 10.416422, 10.434995, 10.453568, 10.472141, 10.490714, 10.5, 10.509286, 10.527859, 10.546432, 10.565005, 10.583578, 10.602151, 10.620723, 10.639296, 10.657869, 10.676442, 10.695015, 10.713587, 10.73216, 10.750733, 10.769306, 10.787879, 10.806452, 10.825024, 10.843597, 10.86217, 10.880743, 10.899316, 10.917889, 10.936461, 10.955034, 10.973607, 10.99218, 11.010753, 11.029326, 11.047898, 11.066471, 11.085044, 11.103617, 11.12219, 11.140762, 11.159335, 11.177908, 11.196481, 11.215054, 11.233627, 11.252199, 11.270772, 11.289345, 11.307918, 11.326491, 11.345064, 11.363636, 11.382209, 11.400782, 11.419355, 11.437928, 11.4565, 11.475073, 11.493646, 11.512219, 11.530792, 11.549365, 11.567937, 11.58651, 11.605083, 11.623656, 11.642229, 11.660802, 11.679374, 11.697947, 11.71652, 11.735093, 11.753666, 11.772239, 11.790811, 11.809384, 11.827957, 11.84653, 11.865103, 11.883675, 11.902248, 11.920821, 11.939394, 11.957967, 11.97654, 11.995112, 12.013685, 12.032258, 12.050831, 12.069404, 12.087977, 12.106549, 12.125122, 12.143695, 12.162268, 12.180841, 12.199413, 12.217986, 12.236559, 12.255132, 12.273705, 12.292278, 12.31085, 12.329423, 12.347996, 12.366569, 12.385142, 12.403715, 12.422287, 12.44086, 12.459433, 12.478006, 12.496579, 12.515152, 12.533724, 12.552297, 12.57087, 12.589443, 12.608016, 12.626588, 12.645161, 12.663734, 12.682307, 12.70088, 12.719453, 12.738025, 12.756598, 12.775171, 12.793744, 12.812317, 12.83089, 12.849462, 12.868035, 12.886608, 12.905181, 12.923754, 12.942326, 12.960899, 12.979472, 12.998045, 13.016618, 13.035191, 13.053763, 13.072336, 13.090909, 13.109482, 13.128055, 13.146628, 13.1652, 13.183773, 13.202346, 13.220919, 13.239492, 13.258065, 13.276637, 13.29521, 13.313783, 13.332356, 13.350929, 13.369501, 13.388074, 13.406647, 13.42522, 13.443793, 13.462366, 13.480938, 13.499511, 13.518084, 13.536657, 13.55523, 13.573803, 13.592375, 13.610948, 13.629521, 13.648094, 13.666667, 13.685239, 13.703812, 13.722385, 13.740958, 13.759531, 13.778104, 13.796676, 13.815249, 13.833822, 13.852395, 13.870968, 13.889541, 13.908113, 13.926686, 13.945259, 13.963832, 13.982405, 14.000978, 14.01955, 14.038123, 14.056696, 14.075269, 14.093842, 14.112414, 14.130987, 14.14956, 14.168133, 14.186706, 14.205279, 14.223851, 14.242424, 14.260997, 14.27957, 14.298143, 14.316716, 14.335288, 14.353861, 14.372434, 14.391007, 14.40958, 14.428152, 14.446725, 14.465298, 14.483871, 14.502444, 14.521017, 14.539589, 14.558162, 14.576735, 14.595308, 14.613881, 14.632454, 14.651026, 14.669599, 14.688172, 14.706745, 14.725318, 14.743891, 14.762463, 14.781036, 14.799609, 14.818182, 14.836755, 14.855327, 14.8739, 14.892473, 14.911046, 14.929619, 14.948192, 14.966764, 14.985337, 15.00391, 15.022483, 15.041056, 15.059629, 15.078201, 15.096774, 15.115347, 15.13392, 15.152493, 15.171065, 15.189638, 15.208211, 15.226784, 15.245357, 15.25, 15.26393, 15.282502, 15.301075, 15.319648, 15.338221, 15.356794, 15.375367, 15.393939, 15.412512, 15.431085, 15.449658, 15.468231, 15.486804, 15.505376, 15.523949, 15.542522, 15.561095, 15.579668, 15.59824, 15.616813, 15.635386, 15.653959, 15.672532, 15.691105, 15.709677, 15.72825, 15.746823, 15.765396, 15.783969, 15.802542, 15.821114, 15.839687, 15.85826, 15.876833, 15.895406, 15.913978, 15.932551, 15.951124, 15.969697, 15.98827, 16.006843, 16.025415, 16.043988, 16.062561, 16.081134, 16.099707, 16.11828, 16.136852, 16.155425, 16.173998, 16.192571, 16.211144, 16.229717, 16.248289, 16.266862, 16.285435, 16.304008, 16.322581, 16.341153, 16.359726, 16.378299, 16.396872, 16.415445, 16.434018, 16.45259, 16.471163, 16.489736, 16.508309, 16.526882, 16.545455, 16.564027, 16.5826, 16.601173, 16.619746, 16.638319, 16.656891, 16.675464, 16.694037, 16.71261, 16.731183, 16.749756, 16.768328, 16.786901, 16.805474, 16.824047, 16.84262, 16.861193, 16.879765, 16.898338, 16.916911, 16.935484, 16.954057, 16.97263, 16.991202, 17.009775, 17.028348, 17.046921, 17.065494, 17.084066, 17.102639, 17.121212, 17.139785, 17.158358, 17.176931, 17.195503, 17.214076, 17.232649, 17.251222, 17.269795, 17.288368, 17.30694, 17.325513, 17.344086, 17.362659, 17.381232, 17.399804, 17.418377, 17.43695, 17.455523, 17.474096, 17.492669, 17.511241, 17.529814, 17.548387, 17.56696, 17.585533, 17.604106, 17.622678, 17.641251, 17.659824, 17.678397, 17.69697, 17.715543, 17.734115, 17.752688, 17.771261, 17.789834, 17.808407, 17.826979, 17.845552, 17.864125, 17.882698, 17.901271, 17.919844, 17.938416, 17.956989, 17.975562, 17.994135, 18.012708, 18.031281, 18.049853, 18.068426, 18.086999, 18.105572, 18.124145, 18.142717, 18.16129, 18.179863, 18.198436, 18.217009, 18.235582, 18.254154, 18.272727, 18.2913, 18.309873, 18.328446, 18.347019, 18.365591, 18.384164, 18.402737, 18.42131, 18.439883, 18.458456, 18.477028, 18.495601, 18.514174, 18.532747, 18.55132, 18.569892, 18.588465, 18.607038, 18.625611, 18.644184, 18.662757, 18.681329, 18.699902, 18.718475, 18.737048, 18.755621, 18.774194, 18.792766, 18.811339, 18.829912, 18.848485, 18.867058, 18.88563, 18.904203, 18.922776, 18.941349, 18.959922, 18.978495, 18.997067, 19.01564, 19.034213, 19.052786, 19.071359, 19.089932, 19.108504, 19.127077, 19.14565, 19.164223, 19.182796, 19.201369, 19.219941, 19.238514, 19.257087, 19.27566, 19.294233, 19.312805, 19.331378, 19.349951, 19.368524, 19.387097, 19.40567, 19.424242, 19.442815, 19.461388, 19.479961, 19.498534, 19.517107, 19.535679, 19.554252, 19.572825, 19.591398, 19.609971, 19.628543, 19.647116, 19.665689, 19.684262, 19.702835, 19.721408, 19.73998, 19.758553, 19.777126, 19.795699, 19.814272, 19.832845, 19.851417, 19.86999, 19.888563, 19.907136, 19.925709, 19.944282, 19.962854, 19.981427, 20.0]
ydata=[-0.0454348, -0.048166066, -0.050971005, -0.053850005, -0.056803457, -0.059831754, -0.062935293, -0.066114475, -0.069369701, -0.072701379, -0.076109916, -0.079595726, -0.083159225, -0.08680083, -0.090520964, -0.094320052, -0.098198523, -0.10215681, -0.10619535, -0.11031457, -0.11451493, -0.11879687, -0.12316083, -0.12760727, -0.13213665, -0.13674943, -0.14144606, -0.14622703, -0.15109279, -0.15604383, -0.16108062, -0.16620365, -0.1714134, -0.17671036, -0.18209503, -0.1875679, -0.19312947, -0.19878026, -0.20452077, -0.21035151, -0.21627301, -0.22228578, -0.22839035, -0.23458724, -0.240877, -0.24726016, -0.25373726, -0.26030885, -0.26697548, -0.2737377, -0.28059607, -0.28755115, -0.29460351, -0.30175372, -0.30900235, -0.31634999, -0.32379721, -0.33134461, -0.33899277, -0.34674229, -0.35459377, -0.36254781, -0.37060503, -0.37876603, -0.38703143, -0.39540184, -0.40387791, -0.41246025, -0.42114949, -0.42994627, -0.43885124, -0.44786504, -0.45698831, -0.46622171, -0.4755659, -0.48502153, -0.49458928, -0.5042698, -0.51406378, -0.52397188, -0.53399479, -0.5441332, -0.55438778, -0.56475923, -0.57524824, -0.58585552, -0.59658176, -0.60742766, -0.61839395, -0.62948132, -0.6406905, -0.6520222, -0.66347714, -0.67505605, -0.68675965, -0.69858868, -0.71054387, -0.72262595, -0.73483567, -0.74717376, -0.75964097, -0.77223805, -0.78496575, -0.7978248, -0.81081598, -0.82394003, -0.83719771, -0.85058978, -0.864117, -0.87778013, -0.89157994, -0.90551719, -0.91959265, -0.93380708, -0.94816125, -0.96265593, -0.97729189, -0.9920699, -1.0069907, -1.0220551, -1.0372639, -1.0526178, -1.0681176, -1.0837641, -1.099558, -1.1155001, -1.1315912, -1.147832, -1.1642233, -1.1807659, -1.1974605, -1.2143078, -1.2313087, -1.2484638, -1.265774, -1.2832399, -1.3008624, -1.318642, -1.3365797, -1.3546761, -1.3729319, -1.3913479, -1.4099247, -1.4286631, -1.4475637, -1.4666274, -1.4858546, -1.5052463, -1.5248029, -1.5445252, -1.5644138, -1.5844694, -1.6046927, -1.6250842, -1.6456445, -1.6663744, -1.6872743, -1.7083449, -1.7295867, -1.7510004, -1.7725864, -1.7943453, -1.8162777, -1.8383839, -1.8606646, -1.8831202, -1.9057512, -1.928558, -1.9515411, -1.9747008, -1.9980375, -2.0215517, -2.0452437, -2.0691138, -2.0931623, -2.1173895, -2.1417957, -2.1663812, -2.1911461, -2.2160906, -2.241215, -2.2665193, -2.2920037, -2.3176682, -2.343513, -2.369538, -2.3957433, -2.4221287, -2.4486943, -2.47544, -2.5023655, -2.5294707, -2.5567555, -2.5842195, -2.6118626, -2.6396842, -2.6676841, -2.6958619, -2.7242171, -2.7527492, -2.7814577, -2.8103419, -2.8394013, -2.868635, -2.8980424, -2.9276227, -2.957375, -2.9872984, -3.017392, -3.0476546, -3.0780853, -3.1086828, -3.139446, -3.1703735, -3.2014641, -3.2327163, -3.2641287, -3.2956996, -3.3274274, -3.3593105, -3.3913471, -3.4235352, -3.455873, -3.4883584, -3.5209894, -3.5537637, -3.586679, -3.6197329, -3.6529231, -3.6862469, -3.7197017, -3.7532848, -3.7869932, -3.820824, -3.8547741, -3.8888404, -3.9230197, -3.9573084, -3.9917032, -4.0262004, -4.0607962, -4.0954868, -4.1302683, -4.1651366, -4.2000873, -4.2351163, -4.2702189, -4.3053907, -4.3406268, -4.3759224, -4.4112725, -4.4466719, -4.4821153, -4.5175973, -4.5531124, -4.5886548, -4.6242187, -4.6597979, -4.6953865, -4.730978, -4.7665661, -4.802144, -4.837705, -4.8732423, -4.9087487, -4.944217, -4.9796398, -5.0150096, -5.0503187, -5.0855592, -5.1207232, -5.1558025, -5.1907887, -5.2256735, -5.2604482, -5.295104, -5.3296322, -5.3640235, -5.3982689, -5.4323589, -5.4662842, -5.5000352, -5.533602, -5.5669749, -5.600144, -5.633099, -5.6658298, -5.6983261, -5.7305775, -5.7625735, -5.7943034, -5.8257567, -5.8569225, -5.8877901, -5.9183486, -5.948587, -5.9784944, -6.0080597, -6.037272, -6.0661201, -6.0945931, -6.1226799, -6.1503694, -6.1776507, -6.2045127, -6.2309447, -6.2569356, -6.2824747, -6.3075514, -6.3321549, -6.3562749, -6.379901, -6.4030228, -6.4256304, -6.4477138, -6.4692632, -6.4902691, -6.5107221, -6.5306132, -6.5499332, -6.5686737, -6.5868261, -6.6043823, -6.6213344, -6.6376748, -6.6533962, -6.6684916, -6.6829544, -6.6967783, -6.7099571, -6.7224854, -6.7343579, -6.7455696, -6.756116, -6.765993, -6.7751968, -6.7837241, -6.791572, -6.7987379, -6.8052197, -6.8110157, -6.8161246, -6.8205454, -6.8242778, -6.8273218, -6.8296776, -6.8313462, -6.8323286, -6.8326266, -6.8322422, -6.8311778, -6.8294363, -6.8270209, -6.8239351, -6.8201831, -6.8157691, -6.810698, -6.8049748, -6.7986049, -6.7915941, -6.7839486, -6.7756746, -6.766779, -6.7572687, -6.7471511, -6.7364336, -6.7251242, -6.7132308, -6.7007617, -6.6877256, -6.6741309, -6.6599868, -6.6453021, -6.6300863, -6.6143487, -6.5980989, -6.5813464, -6.5641012, -6.5463731, -6.528172, -6.5095081, -6.4903915, -6.4708323, -6.4508408, -6.4304273, -6.4096019, -6.3883751, -6.3667571, -6.3447582, -6.3223887, -6.2996587, -6.2765786, -6.2531585, -6.2294084, -6.2053385, -6.1809587, -6.156279, -6.1313091, -6.1060588, -6.0805378, -6.0547556, -6.0287217, -6.0024454, -5.9759359, -5.9492024, -5.9222538, -5.8950991, -5.8677469, -5.8402059, -5.8124845, -5.7845912, -5.756534, -5.7283211, -5.6999605, -5.6714599, -5.6428269, -5.6140691, -5.5851938, -5.5562082, -5.5271194, -5.4979344, -5.4686599, -5.4393026, -5.4098689, -5.3803652, -5.3507977, -5.3211725, -5.2914955, -5.2617726, -5.2320092, -5.2022111, -5.1723834, -5.1425316, -5.1126606, -5.0827755, -5.0528811, -5.0229822, -4.9930833, -4.9631888, -4.9333033, -4.9034308, -4.8735755, -4.8437413, -4.8139323, -4.784152, -4.7544042, -4.7246925, -4.6950201, -4.6653906, -4.6358071, -4.6062727, -4.5767906, -4.5473635, -4.5179944, -4.488686, -4.4594409, -4.4302618, -4.4011511, -4.3721112, -4.3431444, -4.3142529, -4.285439, -4.2567046, -4.2280518, -4.1994826, -4.1709986, -4.1426018, -4.1142939, -4.0860765, -4.0579512, -4.0299194, -4.0019828, -3.9741426, -3.9464002, -3.918757, -3.891214, -3.8637725, -3.8364337, -3.8091985, -3.782068, -3.7550432, -3.7281249, -3.7013142, -3.6746117, -3.6480184, -3.6215349, -3.5951619, -3.5689001, -3.5427502, -3.5167127, -3.4907882, -3.4649771, -3.4392801, -3.4136975, -3.3882298, -3.3628773, -3.3376404, -3.3125194, -3.2875147, -3.2626265, -3.237855, -3.2132005, -3.1886631, -3.1642431, -3.1399405, -3.1157556, -3.0916883, -3.0677389, -3.0439072, -3.0201935, -2.9965976, -2.9731197, -2.9614249, -2.9497596, -2.9265174, -2.903393, -2.8803863, -2.8574973, -2.8347258, -2.8120718, -2.7895351, -2.7671156, -2.7448131, -2.7226275, -2.7005586, -2.6786061, -2.65677, -2.63505, -2.6134458, -2.5919573, -2.5705842, -2.5493262, -2.5281831, -2.5071547, -2.4862406, -2.4654406, -2.4447543, -2.4241816, -2.4037221, -2.3833754, -2.3631413, -2.3430194, -2.3230095, -2.3031111, -2.283324, -2.2636478, -2.2440822, -2.2246267, -2.2052812, -2.1860451, -2.1669182, -2.1479, -2.1289903, -2.1101886, -2.0914945, -2.0729078, -2.0544279, -2.0360546, -2.0177875, -1.9996261, -1.98157, -1.963619, -1.9457726, -1.9280304, -1.910392, -1.892857, -1.8754251, -1.8580958, -1.8408687, -1.8237435, -1.8067198, -1.7897972, -1.7729752, -1.7562535, -1.7396316, -1.7231093, -1.706686, -1.6903615, -1.6741353, -1.658007, -1.6419762, -1.6260425, -1.6102056, -1.594465, -1.5788204, -1.5632714, -1.5478176, -1.5324586, -1.5171941, -1.5020236, -1.4869467, -1.4719632, -1.4570725, -1.4422745, -1.4275685, -1.4129544, -1.3984317, -1.3840001, -1.3696591, -1.3554085, -1.3412479, -1.3271768, -1.313195, -1.2993021, -1.2854978, -1.2717816, -1.2581533, -1.2446125, -1.2311588, -1.217792, -1.2045116, -1.1913173, -1.1782089, -1.1651859, -1.1522481, -1.139395, -1.1266265, -1.1139421, -1.1013415, -1.0888245, -1.0763907, -1.0640398, -1.0517715, -1.0395854, -1.0274814, -1.015459, -1.0035181, -0.99165818, -0.9798791, -0.96818052, -0.95656217, -0.94502375, -0.93356499, -0.92218561, -0.91088534, -0.8996639, -0.88852102, -0.87745644, -0.86646989, -0.85556111, -0.84472985, -0.83397585, -0.82329886, -0.81269863, -0.80217491, -0.79172747, -0.78135606, -0.77106044, -0.76084038, -0.75069566, -0.74062604, -0.7306313, -0.72071122, -0.71086557, -0.70109415, -0.69139674, -0.68177314, -0.67222313, -0.66274651, -0.65334308, -0.64401265, -0.63475503, -0.62557001, -0.61645742, -0.60741706, -0.59844877, -0.58955235, -0.58072764, -0.57197445, -0.56329264, -0.55468201, -0.54614242, -0.53767371, -0.52927571, -0.52094828, -0.51269126, -0.50450451, -0.49638788, -0.48834123, -0.48036443, -0.47245733, -0.46461982, -0.45685175, -0.44915301, -0.44152347, -0.43396302, -0.42647153, -0.4190489, -0.41169501, -0.40440976, -0.39719305, -0.39004478, -0.38296484, -0.37595316, -0.36900963, -0.36213416, -0.35532669, -0.34858711, -0.34191536, -0.33531136, -0.32877505, -0.32230634, -0.31590518, -0.30957151, -0.30330526, -0.29710638, -0.29097482, -0.28491053, -0.27891347, -0.27298358, -0.26712083, -0.26132519, -0.25559662, -0.2499351, -0.24434058, -0.23881306, -0.23335251, -0.22795892, -0.22263226, -0.21737254, -0.21217973, -0.20705384, -0.20199488, -0.19700282, -0.1920777, -0.1872195, -0.18242826, -0.17770397, -0.17304666, -0.16845635, -0.16393307, -0.15947684, -0.15508769, -0.15076567, -0.1465108, -0.14232313, -0.1382027, -0.13414957, -0.13016377, -0.12624537, -0.12239443, -0.118611, -0.11489515, -0.11124695, -0.10766646, -0.10415377, -0.10070894, -0.097332062, -0.094023219, -0.090782496, -0.087609986, -0.084505781, -0.08146998, -0.078502682, -0.075603993, -0.07277402, -0.070012873, -0.067320667, -0.064697519, -0.062143551, -0.059658887, -0.057243655, -0.054897986, -0.052622014, -0.050415878, -0.048279719, -0.046213682, -0.044217916, -0.042292572, -0.041822258, -0.040437806, -0.038653776, -0.036940644, -0.035298577, -0.033727744, -0.032228316, -0.030800471, -0.029444388, -0.028160251, -0.026948245, -0.025808562, -0.024741395, -0.023746942, -0.022825403, -0.021976984, -0.021201892, -0.020500339, -0.01987254, -0.019318715, -0.018839086, -0.018433879, -0.018103324, -0.017847655, -0.017667108, -0.017561925, -0.01753235, -0.017578632, -0.017701022, -0.017899776, -0.018175154, -0.018527418, -0.018956835, -0.019463677, -0.020048218, -0.020710735, -0.021451512, -0.022270833, -0.023168989, -0.024146273, -0.025202982, -0.026339418, -0.027555885, -0.028852694, -0.030230156, -0.031688588, -0.033228312, -0.034849652, -0.036552936, -0.038338498, -0.040206674, -0.042157804, -0.044192233, -0.04631031, -0.048512387, -0.050798822, -0.053169974, -0.055626209, -0.058167896, -0.060795408, -0.063509122, -0.06630942, -0.069196687, -0.072171312, -0.07523369, -0.078384219, -0.0816233, -0.084951341, -0.088368752, -0.091875948, -0.095473349, -0.099161377, -0.10294046, -0.10681103, -0.11077353, -0.1148284, -0.11897607, -0.123217, -0.12755165, -0.13198047, -0.13650393, -0.14112249, -0.14583663, -0.15064681, -0.15555353, -0.16055726, -0.16565851, -0.17085775, -0.17615549, -0.18155223, -0.18704849, -0.19264477, -0.19834159, -0.20413947, -0.21003894, -0.21604053, -0.22214478, -0.22835222, -0.2346634, -0.24107887, -0.24759918, -0.2542249, -0.26095658, -0.2677948, -0.27474013, -0.28179315, -0.28895444, -0.29622458, -0.30360417, -0.31109381, -0.3186941, -0.32640564, -0.33422905, -0.34216494, -0.35021393, -0.35837666, -0.36665374, -0.37504582, -0.38355354, -0.39217754, -0.40091847, -0.40977699, -0.41875376, -0.42784944, -0.4370647, -0.44640021, -0.45585666, -0.46543473, -0.4751351, -0.48495848, -0.49490556, -0.50497704, -0.51517363, -0.52549604, -0.53594499, -0.54652121, -0.55722542, -0.56805836, -0.57902075, -0.59011334, -0.60133688, -0.61269211, -0.6241798, -0.6358007, -0.64755557, -0.65944519, -0.67147033, -0.68363177, -0.69593028, -0.70836666, -0.72094169, -0.73365618, -0.74651091, -0.75950671, -0.77264436, -0.78592469, -0.79934851, -0.81291664, -0.82662991, -0.84048915, -0.85449518, -0.86864884, -0.88295097, -0.89740242, -0.91200403, -0.92675665, -0.94166114, -0.95671835, -0.97192914, -0.98729438, -1.0028149, -1.0184917, -1.0343254, -1.0503172, -1.0664677, -1.0827779, -1.0992486, -1.1158809, -1.1326754, -1.1496332, -1.1667551, -1.184042, -1.2014948, -1.2191144, -1.2369018, -1.2548576, -1.272983, -1.2912788, -1.3097459, -1.3283851, -1.3471974, -1.3661838, -1.385345, -1.404682, -1.4241956, -1.4438869, -1.4637566, -1.4838057, -1.504035, -1.5244455, -1.5450381, -1.5658135, -1.5867728, -1.6079168, -1.6292463, -1.6507623, -1.6724656, -1.694357, -1.7164375, -1.7387078, -1.7611689, -1.7838216, -1.8066667, -1.829705, -1.8529373, -1.8763646, -1.8999875, -1.923807, -1.9478237, -1.9720384, -1.996452, -2.0210651, -2.0458786, -2.0708932, -2.0961095, -2.1215284, -2.1471505, -2.1729764, -2.199007, -2.2252427, -2.2516843, -2.2783324, -2.3051877, -2.3322506, -2.3595217, -2.3870017, -2.414691, -2.4425902, -2.4706997, -2.4990201, -2.5275517, -2.5562949, -2.5852503, -2.6144181, -2.6437987, -2.6733924, -2.7031995, -2.7332203, -2.7634549, -2.7939036, -2.8245666, -2.8554439, -2.8865356, -2.9178419, -2.9493627, -2.981098, -3.0130477]
popt, pcov = curve_fit(func_poly_3, xdata, ydata, method='lm',maxfev = 8866)
plot1 = plt.plot(np.array(xdata), ydata, 'r*', label='original values')
plot2 = plt.plot(np.array(xdata), [func_poly_3(i, *popt) for i in xdata], 'b', label='curvefit values')
plt.show()
scipy.interpolate.interpnd 插值拟合
前两种都限于你得提前知道待拟合的是什么函数, 可不可以通过大量的点插值得到函数呢?
python的scipy.interpolate模块有一维插值函数interp1d,二维插值函数interp2d,多维插值函数interpnd.
在此只对一维插值做演示.
import numpy as np
from scipy.interpolate import interp1d
import matplotlib.pyplot as plt
xdata=[1.0, 1.0185728, 1.0371457, 1.0557185, 1.0742913, 1.0928641, 1.111437, 1.1300098, 1.1485826, 1.1671554, 1.1857283, 1.2043011, 1.2228739, 1.2414467, 1.2600196, 1.2785924, 1.2971652, 1.315738, 1.3343109, 1.3528837, 1.3714565, 1.3900293, 1.4086022, 1.427175, 1.4457478, 1.4643206, 1.4828935, 1.5014663, 1.5200391, 1.5386119, 1.5571848, 1.5757576, 1.5943304, 1.6129032, 1.6314761, 1.6500489, 1.6686217, 1.6871945, 1.7057674, 1.7243402, 1.742913, 1.7614858, 1.7800587, 1.7986315, 1.8172043, 1.8357771, 1.85435, 1.8729228, 1.8914956, 1.9100684, 1.9286413, 1.9472141, 1.9657869, 1.9843597, 2.0029326, 2.0215054, 2.0400782, 2.058651, 2.0772239, 2.0957967, 2.1143695, 2.1329423, 2.1515152, 2.170088, 2.1886608, 2.2072336, 2.2258065, 2.2443793, 2.2629521, 2.2815249, 2.3000978, 2.3186706, 2.3372434, 2.3558162, 2.3743891, 2.3929619, 2.4115347, 2.4301075, 2.4486804, 2.4672532, 2.485826, 2.5043988, 2.5229717, 2.5415445, 2.5601173, 2.5786901, 2.597263, 2.6158358, 2.6344086, 2.6529814, 2.6715543, 2.6901271, 2.7086999, 2.7272727, 2.7458456, 2.7644184, 2.7829912, 2.801564, 2.8201369, 2.8387097, 2.8572825, 2.8758553, 2.8944282, 2.913001, 2.9315738, 2.9501466, 2.9687195, 2.9872923, 3.0058651, 3.0244379, 3.0430108, 3.0615836, 3.0801564, 3.0987292, 3.1173021, 3.1358749, 3.1544477, 3.1730205, 3.1915934, 3.2101662, 3.228739, 3.2473118, 3.2658847, 3.2844575, 3.3030303, 3.3216031, 3.340176, 3.3587488, 3.3773216, 3.3958944, 3.4144673, 3.4330401, 3.4516129, 3.4701857, 3.4887586, 3.5073314, 3.5259042, 3.544477, 3.5630499, 3.5816227, 3.6001955, 3.6187683, 3.6373412, 3.655914, 3.6744868, 3.6930596, 3.7116325, 3.7302053, 3.7487781, 3.7673509, 3.7859238, 3.8044966, 3.8230694, 3.8416422, 3.8602151, 3.8787879, 3.8973607, 3.9159335, 3.9345064, 3.9530792, 3.971652, 3.9902248, 4.0087977, 4.0273705, 4.0459433, 4.0645161, 4.083089, 4.1016618, 4.1202346, 4.1388074, 4.1573803, 4.1759531, 4.1945259, 4.2130987, 4.2316716, 4.2502444, 4.2688172, 4.28739, 4.3059629, 4.3245357, 4.3431085, 4.3616813, 4.3802542, 4.398827, 4.4173998, 4.4359726, 4.4545455, 4.4731183, 4.4916911, 4.5102639, 4.5288368, 4.5474096, 4.5659824, 4.5845552, 4.6031281, 4.6217009, 4.6402737, 4.6588465, 4.6774194, 4.6959922, 4.714565, 4.7331378, 4.7517107, 4.7702835, 4.7888563, 4.8074291, 4.826002, 4.8445748, 4.8631476, 4.8817204, 4.9002933, 4.9188661, 4.9374389, 4.9560117, 4.9745846, 4.9931574, 5.0117302, 5.030303, 5.0488759, 5.0674487, 5.0860215, 5.1045943, 5.1231672, 5.14174, 5.1603128, 5.1788856, 5.1974585, 5.2160313, 5.2346041, 5.2531769, 5.2717498, 5.2903226, 5.3088954, 5.3274682, 5.3460411, 5.3646139, 5.3831867, 5.4017595, 5.4203324, 5.4389052, 5.457478, 5.4760508, 5.4946237, 5.5131965, 5.5317693, 5.5503421, 5.568915, 5.5874878, 5.6060606, 5.6246334, 5.6432063, 5.6617791, 5.6803519, 5.6989247, 5.7174976, 5.7360704, 5.7546432, 5.773216, 5.7917889, 5.8103617, 5.8289345, 5.8475073, 5.8660802, 5.884653, 5.9032258, 5.9217986, 5.9403715, 5.9589443, 5.9775171, 5.9960899, 6.0146628, 6.0332356, 6.0518084, 6.0703812, 6.0889541, 6.1075269, 6.1260997, 6.1446725, 6.1632454, 6.1818182, 6.200391, 6.2189638, 6.2375367, 6.2561095, 6.2746823, 6.2932551, 6.311828, 6.3304008, 6.3489736, 6.3675464, 6.3861193, 6.4046921, 6.4232649, 6.4418377, 6.4604106, 6.4789834, 6.4975562, 6.516129, 6.5347019, 6.5532747, 6.5718475, 6.5904203, 6.6089932, 6.627566, 6.6461388, 6.6647116, 6.6832845, 6.7018573, 6.7204301, 6.7390029, 6.7575758, 6.7761486, 6.7947214, 6.8132942, 6.8318671, 6.8504399, 6.8690127, 6.8875855, 6.9061584, 6.9247312, 6.943304, 6.9618768, 6.9804497, 6.9990225, 7.0175953, 7.0361681, 7.054741, 7.0733138, 7.0918866, 7.1104594, 7.1290323, 7.1476051, 7.1661779, 7.1847507, 7.2033236, 7.2218964, 7.2404692, 7.259042, 7.2776149, 7.2961877, 7.3147605, 7.3333333, 7.3519062, 7.370479, 7.3890518, 7.4076246, 7.4261975, 7.4447703, 7.4633431, 7.4819159, 7.5004888, 7.5190616, 7.5376344, 7.5562072, 7.5747801, 7.5933529, 7.6119257, 7.6304985, 7.6490714, 7.6676442, 7.686217, 7.7047898, 7.7233627, 7.7419355, 7.7605083, 7.7790811, 7.797654, 7.8162268, 7.8347996, 7.8533724, 7.8719453, 7.8905181, 7.9090909, 7.9276637, 7.9462366, 7.9648094, 7.9833822, 8.001955, 8.0205279, 8.0391007, 8.0576735, 8.0762463, 8.0948192, 8.113392, 8.1319648, 8.1505376, 8.1691105, 8.1876833, 8.2062561, 8.2248289, 8.2434018, 8.2619746, 8.2805474, 8.2991202, 8.3176931, 8.3362659, 8.3548387, 8.3734115, 8.3919844, 8.4105572, 8.42913, 8.4477028, 8.4662757, 8.4848485, 8.5034213, 8.5219941, 8.540567, 8.5591398, 8.5777126, 8.5962854, 8.6148583, 8.6334311, 8.6520039, 8.6705767, 8.6891496, 8.7077224, 8.7262952, 8.744868, 8.7634409, 8.7820137, 8.8005865, 8.8191593, 8.8377322, 8.856305, 8.8748778, 8.8934506, 8.9120235, 8.9305963, 8.9491691, 8.9677419, 8.9863148, 9.0048876, 9.0234604, 9.0420332, 9.0606061, 9.0791789, 9.0977517, 9.1163245, 9.1348974, 9.1534702, 9.172043, 9.1906158, 9.2091887, 9.2277615, 9.2463343, 9.2649071, 9.28348, 9.3020528, 9.3206256, 9.3391984, 9.3577713, 9.3763441, 9.3949169, 9.4134897, 9.4320626, 9.4506354, 9.4692082, 9.487781, 9.5063539, 9.5249267, 9.5434995, 9.5620723, 9.5806452, 9.599218, 9.6177908, 9.6363636, 9.6549365, 9.6735093, 9.6920821, 9.7106549, 9.7292278, 9.7478006, 9.7663734, 9.7849462, 9.8035191, 9.8220919, 9.8406647, 9.8592375, 9.8778104, 9.8963832, 9.914956, 9.9335288, 9.9521017, 9.9706745, 9.9892473, 10.00782, 10.026393, 10.044966, 10.063539, 10.082111, 10.100684, 10.119257, 10.13783, 10.156403, 10.174976, 10.193548, 10.212121, 10.230694, 10.249267, 10.26784, 10.286413, 10.304985, 10.323558, 10.342131, 10.360704, 10.379277, 10.397849, 10.416422, 10.434995, 10.453568, 10.472141, 10.490714, 10.5, 10.509286, 10.527859, 10.546432, 10.565005, 10.583578, 10.602151, 10.620723, 10.639296, 10.657869, 10.676442, 10.695015, 10.713587, 10.73216, 10.750733, 10.769306, 10.787879, 10.806452, 10.825024, 10.843597, 10.86217, 10.880743, 10.899316, 10.917889, 10.936461, 10.955034, 10.973607, 10.99218, 11.010753, 11.029326, 11.047898, 11.066471, 11.085044, 11.103617, 11.12219, 11.140762, 11.159335, 11.177908, 11.196481, 11.215054, 11.233627, 11.252199, 11.270772, 11.289345, 11.307918, 11.326491, 11.345064, 11.363636, 11.382209, 11.400782, 11.419355, 11.437928, 11.4565, 11.475073, 11.493646, 11.512219, 11.530792, 11.549365, 11.567937, 11.58651, 11.605083, 11.623656, 11.642229, 11.660802, 11.679374, 11.697947, 11.71652, 11.735093, 11.753666, 11.772239, 11.790811, 11.809384, 11.827957, 11.84653, 11.865103, 11.883675, 11.902248, 11.920821, 11.939394, 11.957967, 11.97654, 11.995112, 12.013685, 12.032258, 12.050831, 12.069404, 12.087977, 12.106549, 12.125122, 12.143695, 12.162268, 12.180841, 12.199413, 12.217986, 12.236559, 12.255132, 12.273705, 12.292278, 12.31085, 12.329423, 12.347996, 12.366569, 12.385142, 12.403715, 12.422287, 12.44086, 12.459433, 12.478006, 12.496579, 12.515152, 12.533724, 12.552297, 12.57087, 12.589443, 12.608016, 12.626588, 12.645161, 12.663734, 12.682307, 12.70088, 12.719453, 12.738025, 12.756598, 12.775171, 12.793744, 12.812317, 12.83089, 12.849462, 12.868035, 12.886608, 12.905181, 12.923754, 12.942326, 12.960899, 12.979472, 12.998045, 13.016618, 13.035191, 13.053763, 13.072336, 13.090909, 13.109482, 13.128055, 13.146628, 13.1652, 13.183773, 13.202346, 13.220919, 13.239492, 13.258065, 13.276637, 13.29521, 13.313783, 13.332356, 13.350929, 13.369501, 13.388074, 13.406647, 13.42522, 13.443793, 13.462366, 13.480938, 13.499511, 13.518084, 13.536657, 13.55523, 13.573803, 13.592375, 13.610948, 13.629521, 13.648094, 13.666667, 13.685239, 13.703812, 13.722385, 13.740958, 13.759531, 13.778104, 13.796676, 13.815249, 13.833822, 13.852395, 13.870968, 13.889541, 13.908113, 13.926686, 13.945259, 13.963832, 13.982405, 14.000978, 14.01955, 14.038123, 14.056696, 14.075269, 14.093842, 14.112414, 14.130987, 14.14956, 14.168133, 14.186706, 14.205279, 14.223851, 14.242424, 14.260997, 14.27957, 14.298143, 14.316716, 14.335288, 14.353861, 14.372434, 14.391007, 14.40958, 14.428152, 14.446725, 14.465298, 14.483871, 14.502444, 14.521017, 14.539589, 14.558162, 14.576735, 14.595308, 14.613881, 14.632454, 14.651026, 14.669599, 14.688172, 14.706745, 14.725318, 14.743891, 14.762463, 14.781036, 14.799609, 14.818182, 14.836755, 14.855327, 14.8739, 14.892473, 14.911046, 14.929619, 14.948192, 14.966764, 14.985337, 15.00391, 15.022483, 15.041056, 15.059629, 15.078201, 15.096774, 15.115347, 15.13392, 15.152493, 15.171065, 15.189638, 15.208211, 15.226784, 15.245357, 15.25, 15.26393, 15.282502, 15.301075, 15.319648, 15.338221, 15.356794, 15.375367, 15.393939, 15.412512, 15.431085, 15.449658, 15.468231, 15.486804, 15.505376, 15.523949, 15.542522, 15.561095, 15.579668, 15.59824, 15.616813, 15.635386, 15.653959, 15.672532, 15.691105, 15.709677, 15.72825, 15.746823, 15.765396, 15.783969, 15.802542, 15.821114, 15.839687, 15.85826, 15.876833, 15.895406, 15.913978, 15.932551, 15.951124, 15.969697, 15.98827, 16.006843, 16.025415, 16.043988, 16.062561, 16.081134, 16.099707, 16.11828, 16.136852, 16.155425, 16.173998, 16.192571, 16.211144, 16.229717, 16.248289, 16.266862, 16.285435, 16.304008, 16.322581, 16.341153, 16.359726, 16.378299, 16.396872, 16.415445, 16.434018, 16.45259, 16.471163, 16.489736, 16.508309, 16.526882, 16.545455, 16.564027, 16.5826, 16.601173, 16.619746, 16.638319, 16.656891, 16.675464, 16.694037, 16.71261, 16.731183, 16.749756, 16.768328, 16.786901, 16.805474, 16.824047, 16.84262, 16.861193, 16.879765, 16.898338, 16.916911, 16.935484, 16.954057, 16.97263, 16.991202, 17.009775, 17.028348, 17.046921, 17.065494, 17.084066, 17.102639, 17.121212, 17.139785, 17.158358, 17.176931, 17.195503, 17.214076, 17.232649, 17.251222, 17.269795, 17.288368, 17.30694, 17.325513, 17.344086, 17.362659, 17.381232, 17.399804, 17.418377, 17.43695, 17.455523, 17.474096, 17.492669, 17.511241, 17.529814, 17.548387, 17.56696, 17.585533, 17.604106, 17.622678, 17.641251, 17.659824, 17.678397, 17.69697, 17.715543, 17.734115, 17.752688, 17.771261, 17.789834, 17.808407, 17.826979, 17.845552, 17.864125, 17.882698, 17.901271, 17.919844, 17.938416, 17.956989, 17.975562, 17.994135, 18.012708, 18.031281, 18.049853, 18.068426, 18.086999, 18.105572, 18.124145, 18.142717, 18.16129, 18.179863, 18.198436, 18.217009, 18.235582, 18.254154, 18.272727, 18.2913, 18.309873, 18.328446, 18.347019, 18.365591, 18.384164, 18.402737, 18.42131, 18.439883, 18.458456, 18.477028, 18.495601, 18.514174, 18.532747, 18.55132, 18.569892, 18.588465, 18.607038, 18.625611, 18.644184, 18.662757, 18.681329, 18.699902, 18.718475, 18.737048, 18.755621, 18.774194, 18.792766, 18.811339, 18.829912, 18.848485, 18.867058, 18.88563, 18.904203, 18.922776, 18.941349, 18.959922, 18.978495, 18.997067, 19.01564, 19.034213, 19.052786, 19.071359, 19.089932, 19.108504, 19.127077, 19.14565, 19.164223, 19.182796, 19.201369, 19.219941, 19.238514, 19.257087, 19.27566, 19.294233, 19.312805, 19.331378, 19.349951, 19.368524, 19.387097, 19.40567, 19.424242, 19.442815, 19.461388, 19.479961, 19.498534, 19.517107, 19.535679, 19.554252, 19.572825, 19.591398, 19.609971, 19.628543, 19.647116, 19.665689, 19.684262, 19.702835, 19.721408, 19.73998, 19.758553, 19.777126, 19.795699, 19.814272, 19.832845, 19.851417, 19.86999, 19.888563, 19.907136, 19.925709, 19.944282, 19.962854, 19.981427, 20.0]
ydata=[-0.00026077789, -9.6432747e-16, -9.6432747e-16, -9.6432747e-16, 0.0, 0.0, 0.0, 0.0, -9.6432747e-16, 0.0, 0.0, 0.0, 0.0, -1.9286549e-15, 0.0, -9.6432747e-16, -9.6432747e-16, 0.0, -9.6432747e-16, 0.0, 0.0, 0.0, -9.6432747e-16, 0.0, 0.0, -9.6432747e-16, -9.6432747e-16, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, -9.6432747e-16, 1.9286549e-15, -9.6432747e-16, -9.6432747e-16, -9.6432747e-16, -9.6432747e-16, 0.0, 0.0, -9.6432747e-16, 0.0, -9.6432747e-16, -9.6432747e-16, 0.0, -9.6432747e-16, -9.6432747e-16, -9.6432747e-16, -9.6432747e-16, 0.0, -9.6432747e-16, -9.6432747e-16, 0.0, 0.0, 0.0, -9.6432747e-16, -9.6432747e-16, 0.0, 0.0, 0.0, 0.0, 0.0, -9.6432747e-16, 0.0, -9.6432747e-16, -9.6432747e-16, 0.0, 0.0, -1.9286549e-15, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, -9.6432747e-16, -9.6432747e-16, 0.0, 0.0, 0.0, -0.00026598827, -0.00074931163, -0.0012412449, -0.0017417588, -0.0022508257, -0.0027684194, -0.0032945152, -0.0038290898, -0.0043721214, -0.0049235899, -0.0054834764, -0.0060517635, -0.0066284354, -0.0072134777, -0.0078068772, -0.0084086225, -0.0090187034, -0.0096371112, -0.010263839, -0.01089888, -0.01154223, -0.012193887, -0.012853847, -0.013522112, -0.014198682, -0.01488356, -0.015576749, -0.016278254, -0.016988082, -0.017706241, -0.018432739, -0.019167587, -0.019910798, -0.020662383, -0.021422357, -0.022190737, -0.022967538, -0.023752779, -0.024546479, -0.025348659, -0.026159341, -0.026978548, -0.027806305, -0.028642636, -0.029487569, -0.030341132, -0.031203354, -0.032074264, -0.032953896, -0.033842281, -0.034739453, -0.035645447, -0.0365603, -0.037484048, -0.03841673, -0.039358386, -0.040309055, -0.04126878, -0.042237603, -0.043215569, -0.044202721, -0.045199105, -0.04620477, -0.047219761, -0.04824413, -0.049277925, -0.050321197, -0.051373999, -0.052436384, -0.053508404, -0.054590116, -0.055681575, -0.056782838, -0.057893962, -0.059015006, -0.06014603, -0.061287093, -0.062438258, -0.063599587, -0.064771142, -0.065952987, -0.067145187, -0.068347809, -0.069560917, -0.07078458, -0.072018866, -0.073263843, -0.074519581, -0.07578615, -0.077063622, -0.078352069, -0.079651562, -0.080962177, -0.082283986, -0.083617065, -0.084961489, -0.086317335, -0.087684679, -0.0890636, -0.090454175, -0.091856483, -0.093270604, -0.094696619, -0.096134608, -0.097584652, -0.099046834, -0.10052124, -0.10200794, -0.10350704, -0.1050186, -0.10654272, -0.10807949, -0.10962898, -0.11119129, -0.1127665, -0.1143547, -0.11595598, -0.11757042, -0.11919812, -0.12083916, -0.12249364, -0.12416165, -0.12584327, -0.1275386, -0.12924773, -0.13097074, -0.13270775, -0.13445883, -0.13622408, -0.13800359, -0.13979746, -0.14160579, -0.14342866, -0.14526617, -0.14711843, -0.14898551, -0.15086752, -0.15276456, -0.15467672, -0.1566041, -0.1585468, -0.16050491, -0.16247853, -0.16446777, -0.1664727, -0.16849345, -0.1705301, -0.17258275, -0.17465151, -0.17673646, -0.17883772, -0.18095538, -0.18308954, -0.1852403, -0.18740776, -0.18959202, -0.19179319, -0.19401135, -0.19624662, -0.19849909, -0.20076886, -0.20305604, -0.20536073, -0.20768302, -0.21002302, -0.21238083, -0.21475655, -0.21715028, -0.21956213, -0.22199219, -0.22444057, -0.22690737, -0.22939269, -0.23189663, -0.23441929, -0.23696078, -0.23952119, -0.24210064, -0.24469921, -0.24731701, -0.24995414, -0.25261071, -0.25528682, -0.25798256, -0.26069804, -0.26343336, -0.26618862, -0.26896392, -0.27175936, -0.27457505, -0.27741108, -0.28026756, -0.28314458, -0.28604225, -0.28896067, -0.29189993, -0.29486014, -0.2978414, -0.30084381, -0.30386746, -0.30691246, -0.30997891, -0.3130669, -0.31617654, -0.31930792, -0.32246115, -0.32563632, -0.32883352, -0.33205287, -0.33529445, -0.33855837, -0.34184472, -0.3451536, -0.34848511, -0.35183934, -0.35521639, -0.35861637, -0.36203936, -0.36548546, -0.36895477, -0.37244738, -0.37596339, -0.3795029, -0.38306599, -0.38665278, -0.39026334, -0.39389778, -0.39755618, -0.40123865, -0.40494528, -0.40867616, -0.41243138, -0.41621104, -0.42001522, -0.42384404, -0.42769756, -0.43157589, -0.43547912, -0.43940735, -0.44336065, -0.44733912, -0.45134286, -0.45537195, -0.45942649, -0.46350656, -0.46761225, -0.47174366, -0.47590087, -0.48008396, -0.48429304, -0.48852819, -0.49278948, -0.49707703, -0.5013909, -0.50573119, -0.51009799, -0.51449137, -0.51891144, -0.52335826, -0.52783194, -0.53233254, -0.53686017, -0.54141491, -0.54599683, -0.55060602, -0.55524257, -0.55990656, -0.56459807, -0.5693172, -0.57406401, -0.57883859, -0.58364103, -0.5884714, -0.59332979, -0.59821628, -0.60313095, -0.60807388, -0.61304516, -0.61804485, -0.62307305, -0.62812983, -0.63321526, -0.63832944, -0.64347244, -0.64864433, -0.6538452, -0.65907512, -0.66433417, -0.66962243, -0.67493998, -0.68028689, -0.68566323, -0.69106909, -0.69650455, -0.70196966, -0.70746452, -0.7129892, -0.71854377, -0.72412831, -0.72974288, -0.73538758, -0.74106246, -0.7467676, -0.75250308, -0.75826897, -0.76406534, -0.76989227, -0.77574982, -0.78163807, -0.78755709, -0.79350695, -0.79948772, -0.80549948, -0.8115423, -0.81761624, -0.82372138, -0.82985778, -0.83602551, -0.84222466, -0.84845527, -0.85471743, -0.86101121, -0.86733666, -0.87369386, -0.88008288, -0.88650379, -0.89295665, -0.89944153, -0.90595849, -0.91250762, -0.91908896, -0.92570259, -0.93234858, -0.93902698, -0.94573788, -0.95248132, -0.95925738, -0.96606613, -0.97290762, -0.97978193, -0.98668911, -0.99362923, -1.0006024, -1.0076086, -1.0146479, -1.0217204, -1.0288262, -1.0359653, -1.0431378, -1.0503438, -1.0575833, -1.0648563, -1.072163, -1.0795033, -1.0868775, -1.0942854, -1.1017273, -1.1092031, -1.1167129, -1.1242567, -1.1318347, -1.1394469, -1.1470933, -1.154774, -1.1624892, -1.1702387, -1.1780227, -1.1858413, -1.1936944, -1.2015823, -1.2095048, -1.2174622, -1.2254544, -1.2334815, -1.2415435, -1.2496406, -1.2577727, -1.26594, -1.2741424, -1.2823801, -1.2906532, -1.2989615, -1.3073053, -1.3156846, -1.3240994, -1.3325497, -1.3410358, -1.3495575, -1.358115, -1.3667083, -1.3753374, -1.3840025, -1.3927035, -1.4014406, -1.4102138, -1.4190231, -1.4278686, -1.4367503, -1.4456684, -1.4546228, -1.4636136, -1.4726409, -1.4817047, -1.490805, -1.499942, -1.5091157, -1.5183261, -1.5275733, -1.5368573, -1.5461782, -1.555536, -1.5649308, -1.5743627, -1.5838316, -1.5933377, -1.602881, -1.6124616, -1.6220794, -1.6317346, -1.6414272, -1.6511572, -1.6609247, -1.6658225, -1.6707297, -1.6805724, -1.6904527, -1.7003707, -1.7103264, -1.72032, -1.7303513, -1.7404206, -1.7505278, -1.7606729, -1.7708562, -1.7810774, -1.7913369, -1.8016344, -1.8119702, -1.8223443, -1.8327567, -1.8432074, -1.8536966, -1.8642242, -1.8747903, -1.8853949, -1.8960382, -1.90672, -1.9174406, -1.9281998, -1.9389978, -1.9498347, -1.9607104, -1.9716249, -1.9825785, -1.993571, -2.0046025, -2.0156731, -2.0267828, -2.0379317, -2.0491197, -2.060347, -2.0716136, -2.0829195, -2.0942647, -2.1056494, -2.1170735, -2.1285371, -2.1400402, -2.1515828, -2.1631651, -2.174787, -2.1864485, -2.1981498, -2.2098908, -2.2216717, -2.2334923, -2.2453528, -2.2572533, -2.2691936, -2.281174, -2.2931944, -2.3052548, -2.3173553, -2.3294959, -2.3416766, -2.3538976, -2.3661588, -2.3784602, -2.390802, -2.403184, -2.4156065, -2.4280693, -2.4405726, -2.4531163, -2.4657005, -2.4783252, -2.4909905, -2.5036963, -2.5164428, -2.5292299, -2.5420578, -2.5549263, -2.5678355, -2.5807855, -2.5937764, -2.606808, -2.6198805, -2.6329939, -2.6461482, -2.6593434, -2.6725796, -2.6858568, -2.699175, -2.7125343, -2.7259346, -2.739376, -2.7528586, -2.7663823, -2.7799471, -2.7935532, -2.8072005, -2.820889, -2.8346188, -2.8483899, -2.8622023, -2.876056, -2.8899511, -2.9038876, -2.9178655, -2.9318848, -2.9459455, -2.9600477, -2.9741914, -2.9883766, -3.0026033, -3.0168716, -3.0311815, -3.0455329, -3.0599259, -3.0743605, -3.0888368, -3.1033547, -3.1179143, -3.1325156, -3.1471586, -3.1618433, -3.1765698, -3.191338, -3.206148, -3.2209997, -3.2358933, -3.2508287, -3.2658059, -3.2808249, -3.2958858, -3.3109886, -3.3261332, -3.3413197, -3.3565482, -3.3718185, -3.3871308, -3.4024851, -3.4178813, -3.4333194, -3.4487995, -3.4643217, -3.4798858, -3.4954919, -3.51114, -3.5268302, -3.5425624, -3.5583366, -3.5741529, -3.5900113, -3.6059117, -3.6218542, -3.6378388, -3.6538655, -3.6699343, -3.6860452, -3.7021983, -3.7183934, -3.7346307, -3.7509101, -3.7672316, -3.7835953, -3.8000012, -3.8164492, -3.8329394, -3.8494717, -3.8660463, -3.882663, -3.8993219, -3.916023, -3.9327662, -3.9495517, -3.9663794, -3.9832493, -4.0001614, -4.0171157, -4.0341123, -4.051151, -4.068232, -4.0853552, -4.1025207, -4.1197283, -4.1369783, -4.1542704, -4.1716048, -4.1889815, -4.2064004, -4.2238615, -4.2413649, -4.2589105, -4.2764985, -4.2941286, -4.3118011, -4.3295158, -4.3472727, -4.365072, -4.3829135, -4.4007972, -4.4187233, -4.4366916, -4.4547022, -4.4727551, -4.4908503, -4.5089877, -4.5271674, -4.5453895, -4.5636538, -4.5819604, -4.6003093, -4.6187005, -4.637134, -4.6556097, -4.6741278, -4.6926882, -4.7112909, -4.7299359, -4.7486233, -4.7673529, -4.7861249, -4.8049392, -4.8237958, -4.8426947, -4.8616359, -4.8806195, -4.8996454, -4.9187137, -4.9378243, -4.9569773, -4.9761726, -4.9954102, -5.0146902, -5.0340126, -5.0533774, -5.0727845, -5.092234, -5.1117258, -5.1312601, -5.1508368, -5.1704558, -5.1901173, -5.2098212, -5.2295674, -5.2493562, -5.2691873, -5.2890609, -5.3089769, -5.3289354, -5.3489363, -5.3689797, -5.3890656, -5.4091939, -5.4293648, -5.4495781, -5.469834, -5.4901323, -5.4952136, -5.5104732, -5.5308567, -5.5512827, -5.5717512, -5.5922624, -5.6128161, -5.6334124, -5.6540513, -5.6747328, -5.695457, -5.7162238, -5.7370332, -5.7578853, -5.7787801, -5.7997176, -5.8206978, -5.8417208, -5.8627864, -5.8838949, -5.9050461, -5.92624, -5.9474768, -5.9687564, -5.9900789, -6.0114442, -6.0328524, -6.0543034, -6.0757974, -6.0973343, -6.1189141, -6.1405369, -6.1622027, -6.1839115, -6.2056634, -6.2274582, -6.2492962, -6.2711772, -6.2931014, -6.3150686, -6.3370791, -6.3591327, -6.3812295, -6.4033696, -6.4255529, -6.4477794, -6.4700493, -6.4923625, -6.5147191, -6.537119, -6.5595624, -6.5820491, -6.6045793, -6.6271531, -6.6497703, -6.672431, -6.6951354, -6.7178833, -6.7406749, -6.7635101, -6.786389, -6.8093116, -6.832278, -6.8552881, -6.878342, -6.9014398, -6.9245815, -6.947767, -6.9709965, -6.99427, -7.0175874, -7.0409489, -7.0643545, -7.0878041, -7.1112979, -7.1348358, -7.158418, -7.1820444, -7.205715, -7.22943, -7.2531893, -7.276993, -7.3008411, -7.3247336, -7.3486706, -7.3726521, -7.3966782, -7.4207489, -7.4448642, -7.4690242, -7.4932288, -7.5174782, -7.5417724, -7.5661114, -7.5904952, -7.614924, -7.6393976, -7.6639162, -7.6884798, -7.7130884, -7.7377422, -7.762441, -7.7871849, -7.8119741, -7.8368084, -7.8616881, -7.886613, -7.9115832, -7.9365989, -7.9616599, -7.9867663, -8.0119183, -8.0371157, -8.0623588, -8.0876474, -8.1129816, -8.1383614, -8.163787, -8.1892583, -8.2147754, -8.2403382, -8.2659469, -8.2916014, -8.3173019, -8.3430482, -8.3688406, -8.3946789, -8.4205632, -8.4464936, -8.4724701, -8.4984927, -8.5245615, -8.5506764, -8.5768375, -8.6030449, -8.6292985, -8.6555984, -8.6819446, -8.7083371, -8.734776, -8.7612613, -8.787793, -8.8143711, -8.8409956, -8.8676666, -8.8943841, -8.9211481, -8.9479586, -8.9748157, -9.0017193, -9.0286695, -9.0556662, -9.0827096, -9.1097995, -9.1369361, -9.1641192, -9.191349, -9.2186255, -9.2459485, -9.2733182, -9.3007346, -9.3281976, -9.3557072, -9.3832634, -9.4108663, -9.4385159, -9.466212, -9.4939548, -9.5217441, -9.5495801, -9.5774626, -9.6053917, -9.6333673, -9.6613895, -9.6894581, -9.7175732, -9.7457348, -9.7739428, -9.8021972, -9.830498, -9.8588451, -9.8872385, -9.9156781, -9.944164, -9.972696, -10.001274, -10.029898, -10.058569, -10.087285, -10.116047, -10.144855, -10.173709, -10.202608, -10.231554, -10.260545, -10.289581, -10.318663, -10.34779, -10.376963, -10.40618, -10.435443, -10.464751, -10.494104, -10.523502, -10.552944, -10.582431, -10.611963, -10.641539, -10.671159, -10.700824, -10.730533, -10.760285, -10.790082, -10.819922, -10.849805, -10.879733, -10.909703, -10.939716, -10.969773, -10.999872, -11.030014, -11.060198, -11.090425, -11.120694, -11.151005, -11.181357, -11.211751, -11.242187, -11.272663, -11.303181, -11.333739, -11.364338, -11.394978, -11.425657, -11.456377, -11.487136, -11.517934, -11.548772, -11.579648, -11.610563, -11.641517, -11.672509, -11.703538, -11.734605, -11.76571, -11.796851, -11.82803, -11.859244, -11.890495, -11.921781, -11.953103, -11.98446, -12.015852, -12.047278, -12.078738, -12.110232, -12.14176]
# method: 插值方法: 可选 {‘linear’, ‘nearest’, ‘cubic’} 之一
# ‘linear’: 分段线性, ‘nearest’: 最近邻点, ‘cubic’: 三次样条(cubic spline)插值
func = interp1d(xdata, ydata, kind='cubic')
x_new = np.linspace(start=min(xdata), stop=max(xdata), num=10)
y_new = func(x_new)
plot1 = plt.plot(xdata, ydata, 'r', label='original values')
plt.scatter(x_new, y_new) # 此时即为平滑曲线
plt.show()
References
NumPy polyfit | How polyfit function work in NumPy with examples? (educba.com)
python - 如何修复 numpy 中的“polyfit 可能状况不佳”?- 堆栈溢出 (stackoverflow.com)
python数据处理一:使用curve_fit实现曲线拟合_耐心的小黑的博客-CSDN博客_curve_fit python
更多推荐
所有评论(0)