今天在画图的时候,一直找不到直方图的colormap,在谷歌搜索了很多关于palette的信息,最后发现只要把COL
变成COLZ
就可以了!这是对比的图:


通过palette可以详细设置颜色。
画图代码如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
| void testdraw() { TString filedir="/junofs/users/zhaor/Rm107/PMTtest/Defullscan/mcps.txt"; string ss1; ifstream filein(filedir); gStyle->SetOptStat(0); Int_t palette[5]; palette[0] = 15; palette[1] = 20; palette[2] = 23; palette[3] = 30; palette[4] = 32; gStyle->SetPalette(5,palette); Double_t rmax(1.); TH2D* pol_his = new TH2D("polarHist", "polarHist", 36, 0., 2.*TMath::Pi(), 8, 0., rmax); Double_t mu, muerr; for(Int_t i=1; i<=pol_his->GetNbinsX()/2; i++) { getline(filein,ss1); for(Int_t j=1; j<=pol_his->GetNbinsY(); j++) { getline(filein,ss1); istringstream is1(ss1); is1>>mu>>muerr; pol_his->SetBinContent(i+pol_his->GetNbinsX()/2, j, mu); getline(filein,ss1); istringstream is1(ss1); is1>>mu>>muerr; pol_his->SetBinContent(i, j, mu); } } TH2D* dummy_his = new TH2D("dummy", "histo title", 100, -rmax, rmax, 100, -rmax, rmax); TCanvas* c1 = new TCanvas("theCanvas", "theCanvas", 600, 600); dummy_his->Draw("COLZ"); pol_his->Draw("COLZPOL SAME "); pol_his->SetContour(20); }
|
修改数据的显示范围和颜色的深度,可以使用:
1 2
| pol_his->GetZaxis()->SetRangeUser(0,.2); pol_his->SetContour(40);
|
修改后的效果:

此时还有一个问题就是右边的colormap显示不完整,一个简单的办法是直接在图片上拖动进行调整,效果是这样的:

也可以采用添加TPAD的方法,但是会出现一些白边;暂时就这样了。
上一篇:Histogram进行积分
下一篇:物理学与近似