ROOT  6.07/01
Reference Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
multipalette.C
Go to the documentation of this file.
1 /// \file
2 /// \ingroup tutorial_graphs
3 /// Draw color plots using different color palettes.
4 ///
5 /// \macro_image
6 /// \macro_code
7 ///
8 /// \author Olivier Couet
9 
10 #include "TStyle.h"
11 #include "TColor.h"
12 #include "TF2.h"
13 #include "TExec.h"
14 #include "TCanvas.h"
15 
16 void Pal1()
17 {
18  static Int_t colors[50];
19  static Bool_t initialized = kFALSE;
20 
21  Double_t Red[3] = { 1.00, 0.00, 0.00};
22  Double_t Green[3] = { 0.00, 1.00, 0.00};
23  Double_t Blue[3] = { 1.00, 0.00, 1.00};
24  Double_t Length[3] = { 0.00, 0.50, 1.00 };
25 
26  if(!initialized){
27  Int_t FI = TColor::CreateGradientColorTable(3,Length,Red,Green,Blue,50);
28  for (int i=0; i<50; i++) colors[i] = FI+i;
29  initialized = kTRUE;
30  return;
31  }
32  gStyle->SetPalette(50,colors);
33 }
34 
35 void Pal2()
36 {
37  static Int_t colors[50];
38  static Bool_t initialized = kFALSE;
39 
40  Double_t Red[3] = { 1.00, 0.50, 0.00};
41  Double_t Green[3] = { 0.50, 0.00, 1.00};
42  Double_t Blue[3] = { 1.00, 0.00, 0.50};
43  Double_t Length[3] = { 0.00, 0.50, 1.00 };
44 
45  if(!initialized){
46  Int_t FI = TColor::CreateGradientColorTable(3,Length,Red,Green,Blue,50);
47  for (int i=0; i<50; i++) colors[i] = FI+i;
48  initialized = kTRUE;
49  return;
50  }
51  gStyle->SetPalette(50,colors);
52 }
53 
54 TCanvas* multipalette() {
55  TCanvas *c3 = new TCanvas("c3","C3",0,0,600,400);
56  c3->Divide(2,1);
57  TF2 *f3 = new TF2("f3","0.1+(1-(x-2)*(x-2))*(1-(y-2)*(y-2))",1,3,1,3);
58  f3->SetLineWidth(1);
59  f3->SetLineColor(kBlack);
60 
61  c3->cd(1);
62  f3->Draw("surf1");
63  TExec *ex1 = new TExec("ex1","Pal1();");
64  ex1->Draw();
65  f3->Draw("surf1 same");
66 
67  c3->cd(2);
68  f3->Draw("surf1");
69  TExec *ex2 = new TExec("ex2","Pal2();");
70  ex2->Draw();
71  f3->Draw("surf1 same");
72 
73  return c3;
74 }
virtual void SetLineWidth(Width_t lwidth)
Definition: TAttLine.h:57
virtual void Draw(Option_t *option="")
Draw this function with its current attributes.
Definition: TF2.cxx:216
R__EXTERN TStyle * gStyle
Definition: TStyle.h:423
Definition: Rtypes.h:60
TVirtualPad * cd(Int_t subpadnumber=0)
Set current canvas & pad.
Definition: TCanvas.cxx:659
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
const Bool_t kFALSE
Definition: Rtypes.h:92
virtual void Draw(Option_t *option="")
Default Draw method for all objects.
Definition: TObject.cxx:254
virtual void SetLineColor(Color_t lcolor)
Definition: TAttLine.h:54
A 2-Dim function with parameters.
Definition: TF2.h:33
The Canvas class.
Definition: TCanvas.h:48
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:1073
TExec is a utility class that can be used to execute a C++ command when some event happens in a pad...
Definition: TExec.h:30
const Bool_t kTRUE
Definition: Rtypes.h:91
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:1431
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:1445