python - 使用 matplotlib 将误差线应用于堆叠直方图
问题描述
我有手动计算的(系统)误差线,我想把它放在堆叠直方图的顶部。
我已经能够成功地为常规(非堆叠)直方图箱做到这一点。
我不确定如何准确调用堆叠直方图的 bin 中心和 bin 值,以便能够在顶部绘制误差线。我这样做对吗?如何将误差条放在堆叠箱的顶部?
这是 jupyter 笔记本代码:
fig = plt.figure(figsize=(12,7))
BINS = np.linspace(0,10,11)
xstacked = [df_Event_beam_off['N_sps50'].values,df_Event_overlay['N_sps50'].values]
LABELS = ['Off Beam','Overlay']
plt.hist(xstacked,bins=BINS,histtype='stepfilled',label=LABELS,weights=WEIGHTS_Event_neutrino,stacked=True)
vals_ON_stat,bine_ON_stat = np.histogram(df_Event_beam_on['N_sps50'].values,bins=BINS,weights=weightsON_Event_neutrino)
binc_ON_stat = 0.5*(bine_ON_stat[1:]+bine_ON_stat[:-1])
vals_ON_stat = vals_ON_stat.astype(float)
errs_ON_stat = np.sqrt(vals_ON_stat)
total_error_stacked= np.sqrt((errs_Off_stat)**2+(errs_Overlay_stat)**2+(bin_diff_overlay_syst*vals_Overlay_stat)**2)
plt.errorbar(binc_ON_stat,vals_ON_stat,yerr=errs_ON_stat,fmt='o',color='k',markersize=5,label='ON Beam')
plt.grid()
plt.show()
现在,我希望能够为堆叠做类似的事情,如下所示:
plt.errorbar(binc_stacked,vals_stacked,yerr=total_error_stacked,fmt='o',markersize=5,label='Total Error')
这显然会给出一个错误,说明它不能以不同的尺寸/形状进行广播。有什么建议么?
解决方案
推荐阅读
- reactjs - 反应socket io太多连接错误
- node.js - 查找 - 未找到关系 xxx
- sql - Oracle SQL - 如何显示 2 位小数
- amazon-web-services - AWS-RunShellScript 调用 python 脚本但找不到 python 模块
- qt - 如何在 QToolButton 中为指标设置右边距?
- collections - Rust:没有为 struct `std::string::String` 找到名为 `join` 的方法
- firebase - Flutter:每当打开屏幕时自动运行一个函数
- go - 如何与消费者共享 Golang 包测试数据文件?
- python - python中的多部分表单数据请求(发送2个文件和其他字段数据)
- git - Git新的孤立分支删除所有历史记录减小大小