登录后复制 import numpy as np x = np.arange(0, len(y_list), 1) y = np.array(y_list) fit_result = np.polyfit(x, y, 3) print(fit_result) import matplotlib.pyplot as plt p1d = np.poly1d(fit_result) y_values = p1d(x) # 也可以用 yvals = np.polyval(fit_result, x) plot1 = plt.plot(x, y, '*', label='original values') plot2 = plt.plot(x, y_values, 'r', label='curve fit values') plt.xlabel('x-axis') plt.ylabel('y-axis') plt.legend(loc=4) plt.title('curve fitting') plt.show() 1.2.3.4.5.6.7.8.9.10.11.12.13.14.15.16.17.18.19.20.21.22.23.24.25.26.27.28.29. 原创作者: guotong1988 转载于: https://blog.51cto.com/guotong1988/11662567