import numpy as np
import matplotlib.pyplot as plt
points = np.array([(333, 195.3267), (500, 223.0235), (1000, 264.5914), (2000, 294.8728
), (5000, 328.3523), (10000, 345.4688)])
# get x and y vectors
x = points[:,0]
y = points[:,1]
# calculate polynomial
z = np.polyfit(x, y, 3)
f = np.poly1d(z)
# calculate new x's and y's
x_new = np.linspace(x[0], x[-1], 50)
y_new = f(x_new)
plt.plot(x,y,'o', x_new, y_new)
plt.xlim([x[0]-1, x[-1] + 1 ])
plt.show()
因此,此脚本为插入的数据创建多项式拟合。我想使用多边形文本功能或某些功能来打印曲线拟合的公式。我对Python很陌生。
答案 0 :(得分:2)
from numpy.polynomial import polynomial as P
c, stats = P.polyfit(x,y,3,full=True)
现在,您可以通过打印c
和ssr统计信息来获得系数数组!
文档中的示例非常容易理解! https://docs.scipy.org/doc/numpy/reference/generated/numpy.polynomial.polynomial.polyfit.html