python拟合曲线为什么画的图中一条曲线一条直线?给定了函数形式让程序拟合的。
import matplotlib.pyplot as plt
import numpy as np
from scipy.optimize import curve_fit
#去掉了最后一个水平
# x就是等效应变
def dfin(x, a, b, c):
return (a*z**b-30.0)*(1.0-np.exp(-np.log(2.0*(x/ee)**c)))+30.0
# D初始晶粒尺寸
D = 30.0
# z不同温度需要重新输入
z = 1.92*10**20
ee = 0.0016*D**0.2709*z**0.1147
# 给出x、y对应坐标,即给出等效应变和对应的真实最终晶粒尺寸
x = [0.74,0.69,0.56,0.41,0.3,0.21,0.15,0.12,
1.38,1.33,1.18,1.01,0.82,0.64,0.48,0.35]
x = np.array(x)
num = [26,29,28,30,31,40,39,41,
21,22,23,24,23,27,28,30]
y = np.array(num)
# 非线性最小二乘法拟合
parameter_bounds = ([15*10**5,-0.25,0],[np.inf,0,3])
popt, pcov = curve_fit(dfin, x, y, bounds=parameter_bounds)
# 获取popt里面拟合系数
print(popt)
a = popt[0]
b = popt[1]
c = popt[2]
yvals = dfin(x, a, b, c)
print('系数a:', a)
print('系数b:', b)
print('系数c:', c)
print('系数yvals:', yvals)
# 绘图
plot1 = plt.plot(x, y, 's')
plot2 = plt.plot(x, yvals, 'r')
plt.xlabel('ε')
plt.ylabel('d')
plt.title('1120,v=14,zhui')
plt.show()
图片如下: