col和colz

今天在画图的时候,一直找不到直方图的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;
//infilestream
ifstream filein(filedir);
gStyle->SetOptStat(0);
//gStyle->SetPalette(55);
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);
// the polar data. X maps to theta, Y maps to R
Double_t mu, muerr;
//fill the histogram with something nice.
for(Int_t i=1; i<=pol_his->GetNbinsX()/2; i++)
{
getline(filein,ss1);//jump the odegree
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);
}
}
//make a dummy histogram to set the axis range from -rmax to rmax in both directions
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"); // draw the dummy histogram first
pol_his->Draw("COLZPOL SAME ");
// now draw the data histogram. If it has "SAME" it will use the first histogram ranges
pol_his->SetContour(20);
}

修改数据的显示范围和颜色的深度,可以使用:

1
2
pol_his->GetZaxis()->SetRangeUser(0,.2);
pol_his->SetContour(40);

修改后的效果:

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

也可以采用添加TPAD的方法,但是会出现一些白边;暂时就这样了。

当前网速较慢或者你使用的浏览器不支持博客特定功能,请尝试刷新或换用Chrome、Firefox等现代浏览器