Logo ROOT   6.14/05
Reference Guide
thstack2palettecolor.C
Go to the documentation of this file.
1 /// \file
2 /// \ingroup tutorial_hist
3 /// \notebook
4 /// Palette coloring for 2D histograms' stack is activated thanks to the option `PFC`
5 /// (Palette Fill Color).
6 /// When this option is given to `THStack::Draw` the histograms in the
7 /// `THStack` get their color from the current color palette defined by
8 /// `gStyle->SetPalette(...)`. The color is determined according to the number of
9 /// histograms.
10 ///
11 /// In this example four 2D histograms are displayed with palette coloring.
12 /// The color of each graph is picked inside the palette number 1.
13 ///
14 /// \macro_image
15 /// \macro_code
16 ///
17 /// \author Olivier Couet
18 
19 void thstack2palettecolor () {
20  gStyle->SetPalette(1);
21  TH2F * h1 = new TH2F("h1","h1",20,0,6,20,-4,4);
22  TH2F * h2 = new TH2F("h2","h1",20,0,6,20,-4,4);
23  TH2F * h3 = new TH2F("h3","h1",20,0,6,20,-4,4);
24  TH2F * h4 = new TH2F("h4","h1",20,0,6,20,-4,4);
25  TH2F * h5 = new TH2F("h5","h1",20,0,6,20,-4,4);
26  h2->Fill(2.,0.,5);
27  h3->Fill(3.,0.,10);
28  h4->Fill(4.,0.,15);
29  h5->Fill(5.,0.,20);
30  THStack * hs = new THStack("hs","Test of palette colored lego stack");
31  hs->Add(h1);
32  hs->Add(h2);
33  hs->Add(h3);
34  hs->Add(h4);
35  hs->Add(h5);
36  hs->Draw("0lego1 PFC");
37 }
The Histogram stack class.
Definition: THStack.h:31
R__EXTERN TStyle * gStyle
Definition: TStyle.h:406
virtual void Draw(Option_t *chopt="")
Draw this multihist with its current attributes.
Definition: THStack.cxx:445
TH1F * h1
Definition: legend1.C:5
2-D histogram with a float per channel (see TH1 documentation)}
Definition: TH2.h:250
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:359
Int_t Fill(Double_t)
Invalid Fill method.
Definition: TH2.cxx:292
THist< 2, float, THistStatContent, THistStatUncertainty > TH2F
Definition: THist.hxx:291
void SetPalette(Int_t ncolors=kBird, Int_t *colors=0, Float_t alpha=1.)
See TColor::SetPalette.
Definition: TStyle.cxx:1637