Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
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
30void 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 }
47}
48
49void 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 }
66}
67
68void 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);
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}
bool Bool_t
Definition RtypesCore.h:63
int Int_t
Definition RtypesCore.h:45
constexpr Bool_t kFALSE
Definition RtypesCore.h:101
double Double_t
Definition RtypesCore.h:59
constexpr Bool_t kTRUE
Definition RtypesCore.h:100
@ kBlack
Definition Rtypes.h:65
R__EXTERN TStyle * gStyle
Definition TStyle.h:433
Color * colors
Definition X3DBuffer.c:21
virtual void SetLineWidth(Width_t lwidth)
Set the line width.
Definition TAttLine.h:43
virtual void SetLineColor(Color_t lcolor)
Set the line color.
Definition TAttLine.h:40
The Canvas class.
Definition TCanvas.h:23
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., Bool_t setPalette=kTRUE)
Static function creating a color table with several connected linear gradients.
Definition TColor.cxx:2613
TExec is a utility class that can be used to execute a C++ command when some event happens in a pad.
Definition TExec.h:26
A 2-Dim function with parameters.
Definition TF2.h:29
void Draw(Option_t *option="") override
Draw this function with its current attributes.
Definition TF2.cxx:259
virtual void Draw(Option_t *option="")
Default Draw method for all objects.
Definition TObject.cxx:274
void SetPalette(Int_t ncolors=kBird, Int_t *colors=nullptr, Float_t alpha=1.)
See TColor::SetPalette.
Definition TStyle.cxx:1884
return c3
Definition legend3.C:15