Reputation: 69
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:
The dataframe looks like this with 3649 entries:
Upvotes: 3
Views: 9824
Reputation: 43
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!
Upvotes: 3