Reputation: 16605
I am confused by the order of arguments to plt.errorbar
I have the following code in my Python script
plt.errorbar(0.0, 1.0, 0.1, 10.0)
I would assume the order of arguments is: x_data, y_data, x_error, y_error
This agrees with: http://matplotlib.org/1.2.1/examples/pylab_examples/errorbar_demo.html
However, when I run this code I get the following output:
Clearly, x=0.0, y=1.0, x_err=10.0, y_err=0.1
So the x_error and y_error arguments are swapped!
My question is why? Is the documentation wrong? I am so confused!
Upvotes: 2
Views: 424
Reputation: 69116
If you don't use keywords, the order of the arguments is x, y, yerr, xerr
.
From the docs:
Call signature:
errorbar(x, y, yerr=None, xerr=None, fmt='', ecolor=None, elinewidth=None, capsize=None, barsabove=False, lolims=False, uplims=False, xlolims=False, xuplims=False, errorevery=1, capthick=None)
To avoid this, you can use the keywords to make sure you are giving the correct value to the correct argument; then the order doesn't matter. Note that this is how the example you linked to does it too.
So, for your example, you would want to use:
plt.errorbar(0.0, 1.0, xerr=0.1, yerr=10.0)
Upvotes: 5