Logo ROOT   6.10/09
Reference Guide
histpalettecolor.C
Go to the documentation of this file.
1 /// \file
2 /// \ingroup tutorial_hist
3 /// \notebook
4 /// Palette coloring for histogram is activated thanks to the options `PFC`
5 /// (Palette Fill Color), `PLC` (Palette Line Color) and `AMC` (Palette Marker Color).
6 /// When one of these options is given to `TH1::Draw` the histogram get its color
7 /// from the current color palette defined by `gStyle->SetPalette(…)`. The color
8 /// is determined according to the number of objects having palette coloring in
9 /// the current pad.
10 ///
11 /// In this example five histograms are displayed with palette coloring for lines and
12 /// and marker. The histograms are drawn with makers and error bars and one can see
13 /// the color of each histogram is picked inside the default palette `kBird`.
14 ///
15 /// \macro_image
16 /// \macro_code
17 ///
18 /// \author Olivier Couet
19 
20 void histpalettecolor()
21 {
22  TCanvas *C = new TCanvas();
23 
25  gStyle->SetOptStat(0);
26 
27  TH1F *h1 = new TH1F ("h1","Histogram drawn with full circles",100,-4,4);
28  TH1F *h2 = new TH1F ("h2","Histogram drawn with full squares",100,-4,4);
29  TH1F *h3 = new TH1F ("h3","Histogram drawn with full triangles up",100,-4,4);
30  TH1F *h4 = new TH1F ("h4","Histogram drawn with full triangles down",100,-4,4);
31  TH1F *h5 = new TH1F ("h5","Histogram drawn with empty circles",100,-4,4);
32 
33  TRandom3 random;
34  Double_t px,py;
35  for (Int_t i = 0; i < 25000; i++) {
36  random.Rannor(px,py);
37  h1->Fill(px,10.);
38  h2->Fill(px, 8.);
39  h3->Fill(px, 6.);
40  h4->Fill(px, 4.);
41  h5->Fill(px, 2.);
42  }
43 
49 
50  h1->Draw("PLC PMC");
51  h2->Draw("SAME PLC PMC");
52  h3->Draw("SAME PLC PMC");
53  h4->Draw("SAME PLC PMC");
54  h5->Draw("SAME PLC PMC");
55 
56  gPad->BuildLegend();
57 }
virtual Int_t Fill(Double_t x)
Increment bin with abscissa X by 1.
Definition: TH1.cxx:3126
virtual void Rannor(Float_t &a, Float_t &b)
Return 2 numbers distributed following a gaussian with mean=0 and sigma=1.
Definition: TRandom.cxx:460
Random number generator class based on M.
Definition: TRandom3.h:27
R__EXTERN TStyle * gStyle
Definition: TStyle.h:402
THist< 1, float, THistStatContent, THistStatUncertainty > TH1F
Definition: THist.hxx:311
tomato 1-D histogram with a float per channel (see TH1 documentation)}
Definition: TH1.h:551
int Int_t
Definition: RtypesCore.h:41
TH1F * h1
Definition: legend1.C:5
static double C[]
virtual void Draw(Option_t *option="")
Draw this histogram with options.
Definition: TH1.cxx:2851
virtual void SetMarkerStyle(Style_t mstyle=1)
Set the marker style.
Definition: TAttMarker.h:40
const Bool_t kFALSE
Definition: RtypesCore.h:92
The Canvas class.
Definition: TCanvas.h:31
double Double_t
Definition: RtypesCore.h:55
void SetOptStat(Int_t stat=1)
The type of information printed in the histogram statistics box can be selected via the parameter mod...
Definition: TStyle.cxx:1267
void SetOptTitle(Int_t tit=1)
Definition: TStyle.h:309
#define gPad
Definition: TVirtualPad.h:284