-1

我正在编写一个代码来查找导入文件中某些数据的最佳拟合线的最小二乘。线的方程是ax+b我已经计算过a的地方b。要绘制我尝试过的线:

LS_fit_ydata = []
for i in x_data:
    y_new = ((i*b) + a)
    LS_fit_ydata.append(y_new)

matplotlib.pyplot as plt用来绘制我的图表。

没有错误消息,但这条线没有出现在我的图表上。有谁知道出了什么问题?感谢您提供任何帮助。

4

1 回答 1

0

您缺少的是代码中的绘图部分:

# The code you provided
LS_fit_ydata = []
for i in x_data:
    y_new = ((i*b) + a)
    LS_fit_ydata.append(y_new)

# What happens here is you're plotting x against y one by one via the list
plt.plot(x_data, y_new)
# Show the graph
plt.show()
于 2016-05-04T12:17:40.357 回答