pandola
October 31, 2012, 10:15am
1
Dear All,
I am trying to make a graph in which the area between two 1D histograms is filled with a colour.
Up to now I have been unable to do that: I’d like to leave the area between the “lower” histogram and the x-axis uncoloured, and it looks to be impossible.
Thanks for your help,
Luciano
A brutal fix … {
TH1F *h1 = new TH1F("h1","Bottom", 100, -5, 5);
h1->FillRandom("gaus",10000);
TH1F *h2 = new TH1F("h2","Middle", 100, -5, 5);
h2->FillRandom("gaus",30000);
TH1F *h3 = new TH1F("h3","Top", 100, -5, 5);
h3->FillRandom("gaus",50000);
TH1F *h21 = new TH1F(*h2);
h21->SetNameTitle("h21", "Middle minus Bottom");
h21->SetFillColor(kBlue);
h21->Add(h1, -1);
TH1F *h32 = new TH1F(*h3);
h32->SetNameTitle("h32", "Top minus Middle");
h32->SetFillColor(kRed);
h32->Add(h2, -1);
THStack *hs = new THStack("hs", "All");
hs->Add(h1); // "Bottom"
hs->Add(h21); // "Middle minus Bottom"
hs->Add(h32); // "Top minus Middle"
TCanvas *c1 = new TCanvas("c1", "All");
gPad->Modified(); gPad->Update(); // just a precaution
// h1->SetFillColor(0); // "invisible"
// h1->SetFillColor(gPad->GetFrame()->GetFillColor()); // "invisible"
hs->Draw();
#if 1 /* 0 or 1 */
h1->Draw("L SAME");
h2->Draw("L SAME");
h3->Draw("L SAME");
#endif /* 0 or 1 */
}
A smarter brutal fix … {
// http://www.youtube.com/watch?v=Mb3iPP-tHdA
Color_t BackgroundColor = 10; // 10 = "A Whiter Shade of Pale"
gStyle->SetCanvasColor(BackgroundColor);
gStyle->SetTitleFillColor(BackgroundColor);
gStyle->SetStatColor(BackgroundColor);
TH1F *h1 = new TH1F("h1", "Bottom", 100, -5, 5);
h1->SetFillColor(BackgroundColor);
h1->FillRandom("gaus", 10000);
TH1F *h2 = new TH1F("h2", "Middle", 100, -5, 5);
h2->SetFillColor(kBlue);
h2->FillRandom("gaus", 30000);
TH1F *h3 = new TH1F("h3", "Top", 100, -5, 5);
h3->SetFillColor(kRed);
h3->FillRandom("gaus", 50000);
TCanvas *c1 = new TCanvas("c1", "All");
// c1->SetFillColor(BackgroundColor);
h3->Draw("H"); // "Top"
h2->Draw("H SAME"); // "Middle"
h1->Draw("H SAME"); // "Bottom"
}