// Use a THStack to show a 2-D hist with cells with different colors // run this example with the two options // root > .x multicolor.C // root > .x multicolor.C(1) //Author: Rene Brun #include "TCanvas.h" #include "TH2.h" #include "THStack.h" #include "TRandom.h" void multicolor(Int_t stack=0) { TCanvas *c1 = new TCanvas; Int_t nbins = 20; TH2F *h1 = new TH2F("h1","h1",nbins,-4,4,nbins,-4,4); h1->SetFillColor(kGreen); TH2F *h2 = new TH2F("h2","h2",nbins,-4,4,nbins,-4,4); h2->SetFillColor(kYellow); TH2F *h3 = new TH2F("h3","h3",nbins,-4,4,nbins,-4,4); h3->SetFillColor(kRed); THStack *hs = new THStack("hs","three plots"); hs->Add(h1); hs->Add(h2); hs->Add(h3); TRandom r; Int_t i; for (i=0;i<20000;i++) h1->Fill(r.Gaus(),r.Gaus()); for(int i = 0 ; i < nbins ; i++) { for (int j = 0 ; j < nbins ; j++) { Int_t bin = h1->GetBin(i,j); Double_t content = h1->GetBinContent(bin); if (content > 150 && content < 300) { h1->SetBinContent(bin,0); h2->SetBinContent(bin,content); h3->SetBinContent(bin,0); } else if (content >= 300) { h1->SetBinContent(bin,0); h2->SetBinContent(bin,0); h3->SetBinContent(bin,content); } } } hs->Draw("lego1"); hs->GetXaxis()->LabelsOption("v"); hs->GetXaxis()->SetLabelSize(0.03); h1->GetXaxis()->SetBinLabel(1, "new"); // attempt 1 h2->GetYaxis()->SetBinLabel(1, "new"); // attempt 2 (who knows...) //h2->GetYaxis()->SetBinLabel(5, "new"); gPad->Modified(); TCanvas *c2 = new TCanvas; c2->cd(); h2->Draw(); c2->Modified(); }