使用Python拟合并绘制折线图
发布时间
阅读量:
阅读量
多项式拟合并绘制折线图并打印出拟合多项式
直接展示代码内容
from pylab import *
mpl.rcParams['font.sans-serif'] = ['SimHei']
mpl.rcParams["font.sans-serif"] = ["SimHei"]
mpl.rcParams["axes.unicode_minus"] = False
x = [1, 2, 3, 4, 5, 6]
y = np.array([0.65, 0.78, 0.85, 0.90, 0.84, 0.82])
y1 = np.array([0.66, 0.76, 0.84, 0.88, 0.85, 0.83])
z1 = np.polyfit(x, y, 3) # 用3次多项式拟合
z2 = np.polyfit(x, y1, 3) # 用3次多项式拟合
p1 = np.poly1d(z1)
p2 = np.poly1d(z2)
plt.figure(figsize=(10, 6))
print(p1) # 在屏幕上打印拟合多项式
yvals = p1(x) # 也可以使用yvals=np.polyval(z1,x)
yva
全部评论 (0)
还没有任何评论哟~
