How do I plot a bar plot from a data frame and a 95% confidence interval in the same graph using matplotlib on python(using the yerr arguement if possible). The plot should look like:
Asked
Active
Viewed 9,460 times
3

Sourav
- 69
- 1
- 8
-
See the first answer to this question http://stackoverflow.com/questions/30385975/seaborn-factor-plot-custom-error-bars it should do the trick. – marillion Mar 23 '17 at 20:58
1 Answers
3
Try this:
import pandas as pd
import matplotlib.pyplot as plt
from scipy import stats
mean = df.mean(axis = 1)
std = df.std(axis = 1)
n= df.shape[1]
yerr = std / np.sqrt(n) * stats.t.ppf(1-0.05/2, n - 1)
plt.figure()
plt.bar(range(df.shape[0]), mean, yerr = yerr)
plt.show()
Good luck!

Dani Opitz
- 43
- 6