因此,我计算了一组具有正态分布的数据的置信区间,我想将其绘制为数据均值条形图上的胡须.我尝试对plt.bar使用yerr参数,但它计算标准偏差而不是自信区间.我想在条形图上看到相同的胡须可视化.我有自信的时间间隔:
[(29600.87,39367.28),(37101.74,42849.60),(33661.12,41470.25),(46019.20,49577.80)]
这是我的代码,我尝试用自信的水平提供yerr参数,但效果不是很好.
means=[np.mean(df.iloc[x]) for x in range(len(df.index))]
CI=[st.t.interval(0.95, len(df.iloc[x])-1, loc=np.mean(df.iloc[x]), scale=st.sem(df.iloc[x])) for x in range(len(df.index))]
plt.figure()
plt.bar(x_axis, means, color='r',yerr=np.reshape(CI,(2,4))
plt.xticks(np.arange(1992,1996,1))
Run Code Online (Sandbox Code Playgroud)
这是我得到的情节: