Logo ROOT  
Reference Guide
thstackpalettecolor.C File Reference

Detailed Description

View in nbviewer Open in SWAN Palette coloring for histograms' stack is activated thanks to the options PFC (Palette Fill Color), PLC (Palette Line Color) and AMC (Palette Marker Color). When one of these options 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 histograms are displayed with palette coloring. The color of each histogram is picked inside the palette kOcean.

void thstackpalettecolor()
{
auto hs = new THStack("hs","Stacked 1D histograms colored using kOcean palette");
// Create three 1-d histograms and add them in the stack
auto h1st = new TH1F("h1st","test hstack",100,-4,4);
h1st->FillRandom("gaus",20000);
hs->Add(h1st);
auto h2st = new TH1F("h2st","test hstack",100,-4,4);
h2st->FillRandom("gaus",15000);
hs->Add(h2st);
auto h3st = new TH1F("h3st","test hstack",100,-4,4);
h3st->FillRandom("gaus",10000);
hs->Add(h3st);
// draw the stack
hs->Draw("pfc nostack");
}
Author
Olivier Couet

Definition in file thstackpalettecolor.C.

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
gStyle
R__EXTERN TStyle * gStyle
Definition: TStyle.h:412
TH1::FillRandom
virtual void FillRandom(const char *fname, Int_t ntimes=5000)
Fill histogram following distribution in function fname.
Definition: TH1.cxx:3444
kOcean
@ kOcean
Definition: TColor.h:110
TStyle::SetPalette
void SetPalette(Int_t ncolors=kBird, Int_t *colors=0, Float_t alpha=1.)
See TColor::SetPalette.
Definition: TStyle.cxx:1785
TH1F
1-D histogram with a float per channel (see TH1 documentation)}
Definition: TH1.h:572
THStack::Draw
virtual void Draw(Option_t *chopt="")
Draw this multihist with its current attributes.
Definition: THStack.cxx:447