I want to plot 2D data points with errors on each axis in python. I have used errorbar from matplotlib:

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)

But it shows only errors on y-axis. I have no idea why.

The plot:

The plot

1 Answers

0
Gio On Best Solutions

There is nothing wrong with your code. The problem is the relative value of the errors and the x data. You are simply not able to see the bars. To understand the issue look at the following two examples:

Invert the x and y coordinates:

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

enter image description here

Reduce the value of your 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)

enter image description here