# 用Numpy来实现数据拟合 import matplotlib.pyplot as plt import numpy as np x = np.linspace(300,400,20) y = x + np.random.randint(5,20,20) # 随机取5到10中间20个数 poly = np.polyfit(x,y,deg=1) z = np.polyval(poly, x) plt.plot(x, y, '*') plt.plot(x, z) plt.show()
绘制出下图



