文章目录
前言
使用Numpy进行线性拟合并出图
一、核心函数
def linear_fit(x, y): # 拟合函数
# z = np.polyfit(np.log(x), np.log(y), 1)
z = np.polyfit(x, y, 1)
return [z[0], z[1]]
def plotfit(X, Y, w, b): # 散点拟合图
plt.rcParams['font.family'] = ["Times New Roman"]
matplotlib.rcParams['font.family'] = 'Times New Roman'
# 使字体同非 mathtext 字的字体,此处即 Times New Roman
matplotlib.rcParams['mathtext.default'] = 'regular'
plt.rc('font', family='times new roman')
fig, ax = plt.subplots(1, figsize=(6, 5))
plt.scatter(X, Y, c='black', label