python3-曲线拟合(polyfit/polyval)

【polyfit】多项式曲线拟合

【polyval】多项式曲线求值

import numpy as np
import matplotlib.pyplot as plt


x_data = np.random.rand(100).astype(np.float32)
y_data = x_data * 0.1 + 0.3

poly = np.polyfit(x_data, y_data, deg = 1)

plt.plot(x_data, y_data, 'o')
plt.plot(x_data, np.polyval(poly, x_data))
plt.show()

效果:

python3-曲线拟合(polyfit/polyval)_第1张图片 

 

你可能感兴趣的:(Python)