我无法使用python绘制以下数据

2024-04-29 22:49:12 发布

您现在位置:Python中文网/ 问答频道 /正文

我有4(a,x,y,z)列,其中第2列的数据仅在小数点后的第1列。 我可以使用第二、第三和第四列绘制曲线,但需要使用第一列代替第二列。 我没有得到预期的结果 数据:

 2457455.1457512  .1457512  18.1475 0.0345905 
 2457455.1492267  .1492267  18.866  0.0523474
 2457455.1527023  .1527023  19.676  0.078232
 2457455.1561779  .1561779  19.4285 0.0822207
 2457455.1596534  .1596534  18.531  0.0434684
 2457455.1631289  .1631289  17.9085 0.0306676

我尝试重新定位x,认为这可能会有所帮助,并分享了预期的图像:

[https://i.stack.imgur.com/LntG4.png1

我用于获得预期结果的代码:

popt, pcov = curve_fit(line,x,y)
yfit = line(x,*popt)
print(x,yfit)
print ("a =", popt[0], "+/-", pcov[0,0]**0.5)
print( "b =", popt[1], "+/-", pcov[1,1]**0.5)
print ("c =", popt[2], "+/-", pcov[2,2]**0.5)
plt.errorbar(x,y, yerr=z, ls = "none", marker = 'o', color ="blue")
plt.errorbar(x,yfit, color='green')
plt.xlabel("HJD(2457455+)", size = 15)
plt.ylabel("R(mag)",  size = 15)
#plt.legend(loc = 1)
plt.savefig("curve_fit.pdf")
plt.show()
    

有谁能指导我如何使用第1列进行绘图


Tags: 数据sizeline绘制plt曲线fitcolor