Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
multipalette.C
Go to the documentation of this file.
1 /// \file
2 /// \ingroup tutorial_graphs
3 /// \notebook
4 /// Draw color plots using different color palettes.
5 ///
6 /// As only one palette is active, one need to use `TExec` to be able to
7 /// display plots using different palettes on the same pad.
8 ///
9 /// When a pad is painted, all its elements are painted in the sequence
10 /// of Draw calls (See the difference between Draw and Paint in the TPad documentation);
11 /// for TExec it executes its command - which in the following
12 /// example sets palette for painting all objects painted afterwards.
13 /// If in the next pad another TExec changes the palette, it doesn’t affect the
14 /// previous pad which was already painted, but it will affect the current and
15 /// those painted later.
16 ///
17 /// The following macro illustrate this feature.
18 ///
19 /// \macro_image
20 /// \macro_code
21 ///
22 /// \author Olivier Couet
23 
24 #include "TStyle.h"
25 #include "TColor.h"
26 #include "TF2.h"
27 #include "TExec.h"
28 #include "TCanvas.h"
29 
30 void Pal1()
31 {
32  static Int_t colors[50];
33  static Bool_t initialized = kFALSE;
34 
35  Double_t Red[3] = { 1.00, 0.00, 0.00};
36  Double_t Green[3] = { 0.00, 1.00, 0.00};
37  Double_t Blue[3] = { 1.00, 0.00, 1.00};
38  Double_t Length[3] = { 0.00, 0.50, 1.00 };
39 
40  if(!initialized){
41  Int_t FI = TColor::CreateGradientColorTable(3,Length,Red,Green,Blue,50);
42  for (int i=0; i<50; i++) colors[i] = FI+i;
43  initialized = kTRUE;
44  return;
45  }
46  gStyle->SetPalette(50,colors);
47 }
48 
49 void Pal2()
50 {
51  static Int_t colors[50];
52  static Bool_t initialized = kFALSE;
53 
54  Double_t Red[3] = { 1.00, 0.50, 0.00};
55  Double_t Green[3] = { 0.50, 0.00, 1.00};
56  Double_t Blue[3] = { 1.00, 0.00, 0.50};
57  Double_t Length[3] = { 0.00, 0.50, 1.00 };
58 
59  if(!initialized){
60  Int_t FI = TColor::CreateGradientColorTable(3,Length,Red,Green,Blue,50);
61  for (int i=0; i<50; i++) colors[i] = FI+i;
62  initialized = kTRUE;
63  return;
64  }
65  gStyle->SetPalette(50,colors);
66 }
67 
68 void multipalette() {
69  TCanvas *c3 = new TCanvas("c3","C3",0,0,600,400);
70  c3->Divide(2,1);
71  TF2 *f3 = new TF2("f3","0.1+(1-(x-2)*(x-2))*(1-(y-2)*(y-2))",1,3,1,3);
72  f3->SetLineWidth(1);
73  f3->SetLineColor(kBlack);
74 
75  c3->cd(1);
76  f3->Draw("surf1");
77  TExec *ex1 = new TExec("ex1","Pal1();");
78  ex1->Draw();
79  f3->Draw("surf1 same");
80 
81  c3->cd(2);
82  f3->Draw("surf1");
83  TExec *ex2 = new TExec("ex2","Pal2();");
84  ex2->Draw();
85  f3->Draw("surf1 same");
86 }