Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
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  auto C = new TCanvas();
23 
24  gStyle->SetOptTitle(kFALSE);
25  gStyle->SetOptStat(0);
26 
27  auto h1 = new TH1F ("h1","Histogram drawn with full circles",100,-4,4);
28  auto h2 = new TH1F ("h2","Histogram drawn with full squares",100,-4,4);
29  auto h3 = new TH1F ("h3","Histogram drawn with full triangles up",100,-4,4);
30  auto h4 = new TH1F ("h4","Histogram drawn with full triangles down",100,-4,4);
31  auto h5 = new TH1F ("h5","Histogram drawn with empty circles",100,-4,4);
32 
33  TRandom3 rng;
34  Double_t px,py;
35  for (Int_t i = 0; i < 25000; i++) {
36  rng.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 
44  h1->SetMarkerStyle(kFullCircle);
45  h2->SetMarkerStyle(kFullSquare);
46  h3->SetMarkerStyle(kFullTriangleUp);
47  h4->SetMarkerStyle(kFullTriangleDown);
48  h5->SetMarkerStyle(kOpenCircle);
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 }