Hi,
I need to draw on the same pad some values in colours and also as TEXT with " 5.2f mrad" format and additionally indicate the element numbers with “2i” format. Here is an example code:
{
TCanvas* c = new TCanvas("c", "c", 400, 400);
TH2I* hi = new TH2I("hi", "hi", 2, 0, 2, 2, 0, 2);
hi->SetBinContent(1, 1, 1);
hi->SetBinContent(1, 2, 2);
hi->SetBinContent(2, 1, 3);
hi->SetBinContent(2, 2, 4);
hi->SetStats(kFALSE);
TH2F* hf = new TH2F("hf", "hf", 2, 0, 2, 2, 0, 2);
hf->SetBinContent(1, 1, 4.5);
hf->SetBinContent(1, 2, 0.5);
hf->SetBinContent(2, 1, -3.5);
hf->SetBinContent(2, 2, -4.5);
hf->SetStats(kFALSE);
TH2F* ht = (TH2F*)hf->Clone();
gStyle->SetHistMinimumZero();
gStyle->SetNumberContours(8);
hf->SetMaximum( 4.);
hf->SetMinimum(-4.);
hf->Draw("COLZ2");
gStyle->SetPaintTextFormat("2i");
hi->SetBarOffset( 0.2);
hi->SetMarkerSize(1.8);
hi->Draw("TEXT SAME");
gStyle->SetPaintTextFormat(" 5.2f mrad");
ht->SetBarOffset(-0.2);
ht->SetMarkerSize(1.8);
ht->Draw("TEXT SAME");
}
Unfortunately, the “2i” format is overshadowed by " 5.2f mrad"…
How can it be avoided?
Thanks !
couet
June 21, 2017, 12:34pm
2
{
TCanvas* c = new TCanvas("c", "c", 400, 400);
TH2I* hi = new TH2I("hi", "hi", 2, 0, 2, 2, 0, 2);
hi->SetBinContent(1, 1, 1);
hi->SetBinContent(1, 2, 2);
hi->SetBinContent(2, 1, 3);
hi->SetBinContent(2, 2, 4);
hi->SetStats(kFALSE);
TH2F* hf = new TH2F("hf", "hf", 2, 0, 2, 2, 0, 2);
hf->SetBinContent(1, 1, 4.5);
hf->SetBinContent(1, 2, 0.5);
hf->SetBinContent(2, 1, -3.5);
hf->SetBinContent(2, 2, -4.5);
hf->SetStats(kFALSE);
TH2F* ht = (TH2F*)hf->Clone();
TExec *ex1 = new TExec("ex1","gStyle->SetPaintTextFormat(\"2d\");");
TExec *ex2 = new TExec("ex2","gStyle->SetPaintTextFormat(\" 5.2f mrad\");");
gStyle->SetHistMinimumZero();
gStyle->SetNumberContours(8);
hf->SetMaximum( 4.);
hf->SetMinimum(-4.);
hf->Draw("COLZ2");
ex1->Draw();
hi->SetBarOffset( 0.2);
hi->SetMarkerSize(1.8);
hi->Draw("TEXT SAME");
ex2->Draw();
ht->SetBarOffset(-0.2);
ht->SetMarkerSize(1.8);
ht->Draw("TEXT SAME");
}
Excellent!
Thank you very much, indeed!
At a second glance - not quite.
Works fine only with
TExec *ex1 = new TExec(“ex1”,“gStyle->SetPaintTextFormat(“3.0f”);”);
I’m using 6.08/06 on Fedora 24
Cheers
couet
June 21, 2017, 2:53pm
5
can you post the picture you get ?
The first one is 3.0f
The second is 2d
couet
June 22, 2017, 11:32am
7
It seems the default format “g” works fine
TExec *ex1 = new TExec("ex1","gStyle->SetPaintTextFormat(\"g\");");
TExec *ex2 = new TExec("ex2","gStyle->SetPaintTextFormat(\" 5.2f mrad\");");
system
Closed
July 6, 2017, 12:40pm
9
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.