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++)
43 colors[i] = FI + i;
44 initialized = kTRUE;
45 return;
46 }
48}
49
50void Pal2()
51{
52 static Int_t colors[50];
53 static Bool_t initialized = kFALSE;
54
55 Double_t Red[3] = {1.00, 0.50, 0.00};
56 Double_t Green[3] = {0.50, 0.00, 1.00};
57 Double_t Blue[3] = {1.00, 0.00, 0.50};
58 Double_t Length[3] = {0.00, 0.50, 1.00};
59
60 if (!initialized) {
61 Int_t FI = TColor::CreateGradientColorTable(3, Length, Red, Green, Blue, 50);
62 for (int i = 0; i < 50; i++)
63 colors[i] = FI + i;
64 initialized = kTRUE;
65 return;
66 }
68}
69
70void multipalette()
71{
72 TCanvas *c3 = new TCanvas("c3", "C3", 0, 0, 600, 400);
73 c3->Divide(2, 1);
74 TF2 *f3 = new TF2("f3", "0.1+(1-(x-2)*(x-2))*(1-(y-2)*(y-2))", 1, 3, 1, 3);
75 f3->SetLineWidth(1);
77
78 c3->cd(1);
79 f3->Draw("surf1");
80 TExec *ex1 = new TExec("ex1", "Pal1();");
81 ex1->Draw();
82 f3->Draw("surf1 same");
83
84 c3->cd(2);
85 f3->Draw("surf1");
86 TExec *ex2 = new TExec("ex2", "Pal2();");
87 ex2->Draw();
88 f3->Draw("surf1 same");
89}
bool Bool_t
Definition RtypesCore.h:63
int Int_t
Definition RtypesCore.h:45
constexpr Bool_t kFALSE
Definition RtypesCore.h:94
double Double_t
Definition RtypesCore.h:59
constexpr Bool_t kTRUE
Definition RtypesCore.h:93
@ kBlack
Definition Rtypes.h:65
R__EXTERN TStyle * gStyle
Definition TStyle.h:436
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:2731
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:292
void SetPalette(Int_t ncolors=kBird, Int_t *colors=nullptr, Float_t alpha=1.)
See TColor::SetPalette.
Definition TStyle.cxx:1888
return c3
Definition legend3.C:15