Logo ROOT  
Reference Guide
thstack2palettecolor.C File Reference

Detailed Description

View in nbviewer Open in SWAN Palette coloring for 2D histograms' stack is activated thanks to the option PFC (Palette Fill Color). When this option is given to THStack::Draw the histograms in the THStack get their color from the current color palette defined by gStyle->SetPalette(...). The color is determined according to the number of histograms.

In this example four 2D histograms are displayed with palette coloring. The color of each graph is picked inside the palette number 1.

void thstack2palettecolor () {
auto h1 = new TH2F("h1","h1",20,0,6,20,-4,4);
auto h2 = new TH2F("h2","h1",20,0,6,20,-4,4);
auto h3 = new TH2F("h3","h1",20,0,6,20,-4,4);
auto h4 = new TH2F("h4","h1",20,0,6,20,-4,4);
auto h5 = new TH2F("h5","h1",20,0,6,20,-4,4);
h2->Fill(2.,0.,5);
h3->Fill(3.,0.,10);
h4->Fill(4.,0.,15);
h5->Fill(5.,0.,20);
auto hs = new THStack("hs","Test of palette colored lego stack");
hs->Add(h1);
hs->Add(h2);
hs->Add(h3);
hs->Add(h4);
hs->Add(h5);
hs->Draw("0lego1 PFC");
}
Author
Olivier Couet

Definition in file thstack2palettecolor.C.

TH2F
2-D histogram with a float per channel (see TH1 documentation)}
Definition: TH2.h:251
THStack
Definition: THStack.h:38
THStack::Add
virtual void Add(TH1 *h, Option_t *option="")
add a new histogram to the list Only 1-d and 2-d histograms currently supported.
Definition: THStack.cxx:361
h1
TH1F * h1
Definition: legend1.C:5
gStyle
R__EXTERN TStyle * gStyle
Definition: TStyle.h:412
TH1::Fill
virtual Int_t Fill(Double_t x)
Increment bin with abscissa X by 1.
Definition: TH1.cxx:3274
TH2::Fill
Int_t Fill(Double_t)
Invalid Fill method.
Definition: TH2.cxx:294
TStyle::SetPalette
void SetPalette(Int_t ncolors=kBird, Int_t *colors=0, Float_t alpha=1.)
See TColor::SetPalette.
Definition: TStyle.cxx:1785
THStack::Draw
virtual void Draw(Option_t *chopt="")
Draw this multihist with its current attributes.
Definition: THStack.cxx:447