Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
thstackcolorscheme.C
Go to the documentation of this file.
1/// \file
2/// \ingroup tutorial_hist
3/// \notebook
4/// This example demonstrates how to use the accessible color schemes with THStack.
5/// In this example, the color scheme with six colors is used.
6/// It also shows that the grayscale version is an acceptable alternative.
7///
8/// \macro_image
9/// \macro_code
10///
11/// \author Olivier Couet
12
13void thstackcolorscheme()
14{
15 auto c1 = new TCanvas();
16 auto hs = new THStack("hs","Stacked 1D histograms colored using 6-colors scheme");
17
18 // Create six 1-d histograms and add them in the stack
19 auto h1st = new TH1F("h1st","A",100,-4,4);
20 h1st->FillRandom("gaus",20000);
21 h1st->SetFillColor(kP6Blue);
22 hs->Add(h1st);
23
24 auto h2st = new TH1F("h2st","B",100,-4,4);
25 h2st->FillRandom("gaus",15000);
26 h2st->SetFillColor(kP6Yellow);
27 hs->Add(h2st);
28
29 auto h3st = new TH1F("h3st","C",100,-4,4);
30 h3st->FillRandom("gaus",10000);
31 h3st->SetFillColor(kP6Red);
32 hs->Add(h3st);
33
34 auto h4st = new TH1F("h4st","D",100,-4,4);
35 h4st->FillRandom("gaus",10000);
36 h4st->SetFillColor(kP6Grape);
37 hs->Add(h4st);
38
39 auto h5st = new TH1F("h5st","E",100,-4,4);
40 h5st->FillRandom("gaus",10000);
41 h5st->SetFillColor(kP6Gray);
42 hs->Add(h5st);
43
44 auto h6st = new TH1F("h6st","F",100,-4,4);
45 h6st->FillRandom("gaus",10000);
46 h6st->SetFillColor(kP6Violet);
47 hs->Add(h6st);
48
49 // draw the stack with colors
50 hs->Draw();
51 TLegend *l = gPad->BuildLegend(.8,.55,1.,.9,"","F");
52 l->SetLineWidth(0);
53 l->SetFillStyle(0);
54
55 // draw the stack using gray-scale
56 auto c2 = new TCanvas();
57 c2->SetGrayscale();
58 hs->Draw();
59 l->Draw();
60}
@ kP6Red
Definition Rtypes.h:69
@ kP6Grape
Definition Rtypes.h:69
@ kP6Gray
Definition Rtypes.h:69
@ kP6Yellow
Definition Rtypes.h:69
@ kP6Violet
Definition Rtypes.h:69
@ kP6Blue
Definition Rtypes.h:69
#define gPad
virtual void SetLineWidth(Width_t lwidth)
Set the line width.
Definition TAttLine.h:43
The Canvas class.
Definition TCanvas.h:23
1-D histogram with a float per channel (see TH1 documentation)
Definition TH1.h:623
The Histogram stack class.
Definition THStack.h:40
This class displays a legend box (TPaveText) containing several legend entries.
Definition TLegend.h:23
virtual void Draw(Option_t *option="")
Default Draw method for all objects.
Definition TObject.cxx:292
return c1
Definition legend1.C:41
return c2
Definition legend2.C:14
TLine l
Definition textangle.C:4