logscales.C: Draw parametric functions with log scales | Histograms | rebin.C: this tutorial illustrates how to: |
// 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(kBlue); TH2F *h2 = new TH2F("h2","h2",nbins,-4,4,nbins,-4,4); h2->SetFillColor(kRed); TH2F *h3 = new TH2F("h3","h3",nbins,-4,4,nbins,-4,4); h3->SetFillColor(kYellow); 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 (i=0;i<200;i++) { Int_t ix = (Int_t)r.Uniform(0,nbins); Int_t iy = (Int_t)r.Uniform(0,nbins); Int_t bin = h1->GetBin(ix,iy); Double_t val = h1->GetBinContent(bin); if (val <= 0) continue; if (!stack) h1->SetBinContent(bin,0); if (r.Rndm() > 0.5) { if (!stack) h2->SetBinContent(bin,0); h3->SetBinContent(bin,val); } else { if (!stack) h3->SetBinContent(bin,0); h2->SetBinContent(bin,val); } } hs->Draw("lego1"); } multicolor.C:1 multicolor.C:2 multicolor.C:3 multicolor.C:4 multicolor.C:5 multicolor.C:6 multicolor.C:7 multicolor.C:8 multicolor.C:9 multicolor.C:10 multicolor.C:11 multicolor.C:12 multicolor.C:13 multicolor.C:14 multicolor.C:15 multicolor.C:16 multicolor.C:17 multicolor.C:18 multicolor.C:19 multicolor.C:20 multicolor.C:21 multicolor.C:22 multicolor.C:23 multicolor.C:24 multicolor.C:25 multicolor.C:26 multicolor.C:27 multicolor.C:28 multicolor.C:29 multicolor.C:30 multicolor.C:31 multicolor.C:32 multicolor.C:33 multicolor.C:34 multicolor.C:35 multicolor.C:36 multicolor.C:37 multicolor.C:38 multicolor.C:39 multicolor.C:40 multicolor.C:41 multicolor.C:42 multicolor.C:43 multicolor.C:44 multicolor.C:45 multicolor.C:46 multicolor.C:47 multicolor.C:48 |
|