Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
hist026_THStack_color_scheme.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/// \date October 2024
12/// \author Olivier Couet
13
15{
16 auto c1 = new TCanvas();
17 auto hs = new THStack("hs", "Stacked 1D histograms colored using 6-colors scheme");
18
19 // Create six 1-d histograms and add them in the stack
20 auto h1st = new TH1F("h1st", "A", 100, -4, 4);
21 h1st->FillRandom("gaus", 20000);
22 h1st->SetFillColor(kP6Blue);
23 hs->Add(h1st);
24
25 auto h2st = new TH1F("h2st", "B", 100, -4, 4);
26 h2st->FillRandom("gaus", 15000);
27 h2st->SetFillColor(kP6Yellow);
28 hs->Add(h2st);
29
30 auto h3st = new TH1F("h3st", "C", 100, -4, 4);
31 h3st->FillRandom("gaus", 10000);
32 h3st->SetFillColor(kP6Red);
33 hs->Add(h3st);
34
35 auto h4st = new TH1F("h4st", "D", 100, -4, 4);
36 h4st->FillRandom("gaus", 10000);
37 h4st->SetFillColor(kP6Grape);
38 hs->Add(h4st);
39
40 auto h5st = new TH1F("h5st", "E", 100, -4, 4);
41 h5st->FillRandom("gaus", 10000);
42 h5st->SetFillColor(kP6Gray);
43 hs->Add(h5st);
44
45 auto h6st = new TH1F("h6st", "F", 100, -4, 4);
46 h6st->FillRandom("gaus", 10000);
47 h6st->SetFillColor(kP6Violet);
48 hs->Add(h6st);
49
50 // draw the stack with colors
51 hs->Draw();
52 TLegend *l = gPad->BuildLegend(.8, .55, 1., .9, "", "F");
53 l->SetLineWidth(0);
54 l->SetFillStyle(0);
55
56 // draw the stack using gray-scale
57 auto c2 = new TCanvas();
58 c2->SetGrayscale();
59 hs->Draw();
60 l->Draw();
61}
@ 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
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
#define gPad
virtual void SetLineWidth(Width_t lwidth)
Set the line width.
Definition TAttLine.h:45
The Canvas class.
Definition TCanvas.h:23
1-D histogram with a float per channel (see TH1 documentation)
Definition TH1.h:645
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