【问题标题】:Calculate and plot 95% confidence interval for a given dataframe计算并绘制给定数据帧的 95% 置信区间
【发布时间】:2017-08-16 13:38:48
【问题描述】:

如何在 python 上使用 matplotlib 从数据框中绘制 条形图 和 95% 置信区间(如果可能,使用 yerr 论证)。情节应如下所示:

数据框看起来像这样,有 3649 个条目:

【问题讨论】:

标签: python matplotlib bar-chart


【解决方案1】:

试试这个:

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() 

祝你好运!

【讨论】:

    猜你喜欢
    • 2021-07-05
    • 1970-01-01
    • 1970-01-01
    • 2018-03-09
    • 2020-11-16
    • 1970-01-01
    • 1970-01-01
    • 2017-11-20
    • 1970-01-01
    相关资源
    最近更新 更多