I have (systematic) error bars calculated manually which I want to put on top of a stacked histogram.
I have already been able to successfully do that for regular (not Stacked) histogram bins.
I am not sure of how to exactly call the bin center and bin values for the stacked histogram to be able to plot the error bars on top. Am I doing this the right way? How do I put the error bars on top of the stacked bins?
Here is the jupyter notebook code:
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()
Now, I want to be able to do something similar for stacked, like this:
plt.errorbar(binc_stacked,vals_stacked,yerr=total_error_stacked,fmt='o',markersize=5,label='Total Error')
This obviously gives an error saying it can't broadcast with different sizes/shapes. Any suggestions?