我无法弄清楚如何使用可以在ROOT中执行的matplotlib精确缩放直方图。我不想将区域归一化为1。我想通过我通过外部计算获得的给定值缩放直方图。
我已经尝试过使用density = True选项,我知道这显然不是我想要的。
这是我如何在ROOT中获得正确的直方图:
root [4] tree1->Draw("distance>>h1(110,0,1100)")
Info in <TCanvas::MakeDefCanvas>: created default TCanvas with name c1
root [5] tree2->Draw("distance>>h2(110,0,1100)")
root [6] h2->Scale(0.64156638885)
root [7] h1->Draw("hist")
root [8] h2->Draw("hist same")
root [9] auto legend = new TLegend(0.1,0.7,0.48,0.9);
root [10] legend->AddEntry(h2,"OFF BEAM","l");
root [11] legend->AddEntry(h1,"ON BEAM","l");
root [12] h2->SetLineColor(kRed)
root [13] h1->SetLineColor(kBlue)
root [14] legend->Draw();
root [15] h1->Draw("hist")
root [16] h2->Draw("hist same")
root [17] legend->Draw();
root [18] gStyle->SetOptStat(0)
在这里您可以看到我已经应用了正确的缩放因子0.64156638885,它为我提供了ROOT What I want to see in matplotlib中所需的绘图
这也是我到目前为止在matplotlib中拥有的东西:
import numpy as np
import matplotlib.pylab as plt
import pandas as pd
from root_numpy import root2array
df_Sps_beam_on = pd.DataFrame( root2array( myfile_beam_on,'/gammacorrelation/Sps_Correlationtree' ) )
df_Sps_beam_off = pd.DataFrame( root2array( myfile_beam_off,'/gammacorrelation/Sps_Correlationtree' ) )
plt.hist(df_Sps_beam_on['distance'].values,bins=BINS,histtype='step',lw=2,label='beam_on')
plt.hist(df_Sps_beam_off['distance'].values,bins=BINS,histtype='step',lw=2,label='beam_off')
plt.show()