我想在Python的每个轴上绘制带有错误的2D数据点。我使用了来自matplotlib的errorbar
:
x=[393.995,394.87,422.965,423.84,437.49,438.360,466.965,467.84]
y=[1.2625,0.7575,1.2625,0.7575,1.2625,1.7675,2.2725,2.7775]
errors=[0.486731,0.00955756,0.111786,0.412761,0.240057,0.228817,0.222496 ,0.24288]
errorbar(x, y, xerr=errors, yerr=errors, ecolor='k', fmt='o', capthick=2)
但是它仅显示y轴上的错误。我不知道为什么。
情节:
答案 0 :(得分:0)
您的代码没有错。问题是错误和x
数据的相对值。您根本看不到这些条。要了解此问题,请看以下两个示例:
反转x
和y
坐标:
x=[393.995,394.87,422.965,423.84,437.49,438.360,466.965,467.84]
y=[1.2625,0.7575,1.2625,0.7575,1.2625,1.7675,2.2725,2.7775]
errors=[0.486731,0.00955756,0.111786,0.412761,0.240057,0.228817,0.222496 ,0.24288]
errorbar(y, x, xerr=errors, yerr=errors, ecolor='k', fmt='o', capthick=2) #invert x and y
减少您的x
的价值。
x=[3.93995,3.9487,4.22965,4.2384,4.3749,4.38360,4.66965,4.6784] #x=x/100
y=[1.2625,0.7575,1.2625,0.7575,1.2625,1.7675,2.2725,2.7775]
errors=[0.486731,0.00955756,0.111786,0.412761,0.240057,0.228817,0.222496 ,0.24288]
plt.errorbar(x,y, xerr=errors, yerr=errors, ecolor='k', fmt='o', capthick=2)