计算并绘制给定数据帧的95%置信区间 [英] Calculate and plot 95% confidence interval for a given dataframe
本文介绍了计算并绘制给定数据帧的95%置信区间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何使用python上的matplotlib在同一张图中绘制数据框中的条形图和95%的置信区间(如果可能,请使用yerr).该图应如下所示:
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:
数据帧看起来像这样,有3649个条目:
The dataframe looks like this with 3649 entries:
推荐答案
尝试一下:
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()
祝你好运!
这篇关于计算并绘制给定数据帧的95%置信区间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文