Logo ROOT   6.14/05
Reference Guide
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 /// \macro_image
7 /// \macro_code
8 ///
9 /// \author Olivier Couet
10 
11 #include "TStyle.h"
12 #include "TColor.h"
13 #include "TF2.h"
14 #include "TExec.h"
15 #include "TCanvas.h"
16 
17 void Pal1()
18 {
19  static Int_t colors[50];
20  static Bool_t initialized = kFALSE;
21 
22  Double_t Red[3] = { 1.00, 0.00, 0.00};
23  Double_t Green[3] = { 0.00, 1.00, 0.00};
24  Double_t Blue[3] = { 1.00, 0.00, 1.00};
25  Double_t Length[3] = { 0.00, 0.50, 1.00 };
26 
27  if(!initialized){
28  Int_t FI = TColor::CreateGradientColorTable(3,Length,Red,Green,Blue,50);
29  for (int i=0; i<50; i++) colors[i] = FI+i;
30  initialized = kTRUE;
31  return;
32  }
33  gStyle->SetPalette(50,colors);
34 }
35 
36 void Pal2()
37 {
38  static Int_t colors[50];
39  static Bool_t initialized = kFALSE;
40 
41  Double_t Red[3] = { 1.00, 0.50, 0.00};
42  Double_t Green[3] = { 0.50, 0.00, 1.00};
43  Double_t Blue[3] = { 1.00, 0.00, 0.50};
44  Double_t Length[3] = { 0.00, 0.50, 1.00 };
45 
46  if(!initialized){
47  Int_t FI = TColor::CreateGradientColorTable(3,Length,Red,Green,Blue,50);
48  for (int i=0; i<50; i++) colors[i] = FI+i;
49  initialized = kTRUE;
50  return;
51  }
52  gStyle->SetPalette(50,colors);
53 }
54 
55 TCanvas *multipalette() {
56  TCanvas *c3 = new TCanvas("c3","C3",0,0,600,400);
57  c3->Divide(2,1);
58  TF2 *f3 = new TF2("f3","0.1+(1-(x-2)*(x-2))*(1-(y-2)*(y-2))",1,3,1,3);
59  f3->SetLineWidth(1);
60  f3->SetLineColor(kBlack);
61 
62  c3->cd(1);
63  f3->Draw("surf1");
64  TExec *ex1 = new TExec("ex1","Pal1();");
65  ex1->Draw();
66  f3->Draw("surf1 same");
67 
68  c3->cd(2);
69  f3->Draw("surf1");
70  TExec *ex2 = new TExec("ex2","Pal2();");
71  ex2->Draw();
72  f3->Draw("surf1 same");
73 
74  return c3;
75 }
virtual void SetLineWidth(Width_t lwidth)
Set the line width.
Definition: TAttLine.h:43
virtual void Draw(Option_t *option="")
Draw this function with its current attributes.
Definition: TF2.cxx:241
R__EXTERN TStyle * gStyle
Definition: TStyle.h:406
Definition: Rtypes.h:58
TVirtualPad * cd(Int_t subpadnumber=0)
Set current canvas & pad.
Definition: TCanvas.cxx:688
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
virtual void Draw(Option_t *option="")
Default Draw method for all objects.
Definition: TObject.cxx:195
virtual void SetLineColor(Color_t lcolor)
Set the line color.
Definition: TAttLine.h:40
A 2-Dim function with parameters.
Definition: TF2.h:29
const Bool_t kFALSE
Definition: RtypesCore.h:88
Color * colors
Definition: X3DBuffer.c:19
The Canvas class.
Definition: TCanvas.h:31
double Double_t
Definition: RtypesCore.h:55
virtual void Divide(Int_t nx=1, Int_t ny=1, Float_t xmargin=0.01, Float_t ymargin=0.01, Int_t color=0)
Automatic pad generation by division.
Definition: TPad.cxx:1162
TExec is a utility class that can be used to execute a C++ command when some event happens in a pad...
Definition: TExec.h:28
const Bool_t kTRUE
Definition: RtypesCore.h:87
static Int_t CreateGradientColorTable(UInt_t Number, Double_t *Stops, Double_t *Red, Double_t *Green, Double_t *Blue, UInt_t NColors, Float_t alpha=1.)
Static function creating a color table with several connected linear gradients.
Definition: TColor.cxx:2209
return c3
Definition: legend3.C:15
void SetPalette(Int_t ncolors=kBird, Int_t *colors=0, Float_t alpha=1.)
See TColor::SetPalette.
Definition: TStyle.cxx:1637