p73
March 23, 2017, 1:09pm
1
I superimpose two histograms:
TH1F *data1 = new TH1F("without_KF", "without_KF",100,0,400 );
t1->Project("without_KF", "pi0pi0");
//e_data->Scale(1./scale_e);
data1->Draw();
c->Update();
TH1F *data2 = new TH1F("with_KF", "with_KF",100,0,400);
t2->Project("with_KF", "pi0pi0");
data2->SetLineColor(kRed);
data2->Draw("same");
c->BuildLegend();
Next I want to set Title in result picture. By default it is the name of the 1st drew hist. And I cannot change it. How to set Title in this case properly?
couet
March 23, 2017, 1:12pm
2
The simplest is to change the title of the histogram data1
, either at creation time or using SetTitle
on data1
.
p73
March 23, 2017, 3:34pm
3
It is bad because I set Legend and if I change title of the hist data1
then in legend it will be too.
couet
March 23, 2017, 4:20pm
4
{
auto h1 = new TH1D("h1","h1",100,-2.,2.);
h1->FillRandom("gaus", 100000);
h1->Draw();
auto h2 = new TH1D("h2","h2",100,-2.,2.);
h2->FillRandom("gaus", 50000);
h2->Draw("same");
gPad->Update();
TPaveText* pt = (TPaveText*)gPad->FindObject("title");
TPaveText* ptn = new TPaveText(pt->GetX1(),pt->GetY1(),
pt->GetX2(),pt->GetY2(),"");
ptn->AddText("New Title");
ptn->SetBorderSize(0);
ptn->SetFillColor(0);
ptn->SetTextFont(42);
ptn->Draw();
gPad->BuildLegend();
}
1 Like
p73
March 25, 2017, 6:47am
5
Though it looks like not the way it works and I do not have any alternative. Thank you.
p73
March 25, 2017, 6:57am
6
One more. I want to enlarge text. But if I try ptn->SetTextSize(number) I get no text at all.
How to set text size?
p73
March 25, 2017, 7:05am
7
Sorry it seems like number should be less than zero? Sorry.
couet
March 27, 2017, 8:02am
8
To enlarge the title you should specify the ton box larger. X1 smaller and X2 bigger.
system
Closed
April 10, 2017, 8:02am
9
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.