1

I am trying to plot asymmetric error bars which are really 95% confidence interval. The output that I get is not the desired outcome. I am not sure what part of the code is not giving rise to the desired outcome.

import numpy as np
import matplotlib.pyplot as plt


x = (18,20,22,24,26,28,30,32,34)
apo_average = (1933.877,1954.596,2058.192,2244.664,2265.383,2265.383,2306.821,2534.731,2576.169)
std_apo=(35.88652754,0,179.4326365,35.88652754,0,0,35.88652754,35.88652696,0)
error =  np.array(apo_average)
lower_error_apo=error-((4.303*(np.array(std_apo)))/np.sqrt(3))
higher_error_apo=error+((4.303*(np.array(std_apo)))/np.sqrt(3))
asymmetric_error_apo=[lower_error_apo, higher_error_apo]

fig = plt.figure()
ax = fig.add_subplot(111)
plt.scatter(x,apo_average,marker='o',label="0 Cu", color='none', edgecolor='blue', linewidth='1')
ax.errorbar(x,apo_average,yerr=asymmetric_error_apo, markerfacecolor='blue',markeredgecolor='blue')

The outcome is enter image description here

This is quite unexpected. For instance, I intended to put a lower error for the first error bar to be 1844.723, which doesn't agree with what's shown in the picture. This trend stays the same with every error bars.

1 Answer 1

3

Most of the time it helps to read the documentation which states

xerr/yerr : scalar or array-like, shape(N,) or shape(2,N), optional
If a scalar number, len(N) array-like object, or a N-element array-like object, errorbars are drawn at +/-value relative to the data. Default is None.
If a sequence of shape 2xN, errorbars are drawn at -row1 and +row2 relative to the data.

You therefore need to use the values calculated from the standard deviation directly, instead of subtracting them from or adding them to the mean.

lower_error_apo=(4.303*(np.array(std_apo)))/np.sqrt(3)
higher_error_apo=(4.303*(np.array(std_apo)))/np.sqrt(3)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.