Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
multipalette.C File Reference

Detailed Description

View in nbviewer Open in SWAN Draw color plots using different color palettes.

As only one palette is active, one need to use TExec to be able to display plots using different palettes on the same pad.

When a pad is painted, all its elements are painted in the sequence of Draw calls (See the difference between Draw and Paint in the TPad documentation); for TExec it executes its command - which in the following example sets palette for painting all objects painted afterwards. If in the next pad another TExec changes the palette, it doesn’t affect the previous pad which was already painted, but it will affect the current and those painted later.

The following macro illustrate this feature.

#include "TStyle.h"
#include "TColor.h"
#include "TF2.h"
#include "TExec.h"
#include "TCanvas.h"
void Pal1()
{
static Int_t colors[50];
static Bool_t initialized = kFALSE;
Double_t Red[3] = { 1.00, 0.00, 0.00};
Double_t Green[3] = { 0.00, 1.00, 0.00};
Double_t Blue[3] = { 1.00, 0.00, 1.00};
Double_t Length[3] = { 0.00, 0.50, 1.00 };
if(!initialized){
Int_t FI = TColor::CreateGradientColorTable(3,Length,Red,Green,Blue,50);
for (int i=0; i<50; i++) colors[i] = FI+i;
initialized = kTRUE;
return;
}
}
void Pal2()
{
static Int_t colors[50];
static Bool_t initialized = kFALSE;
Double_t Red[3] = { 1.00, 0.50, 0.00};
Double_t Green[3] = { 0.50, 0.00, 1.00};
Double_t Blue[3] = { 1.00, 0.00, 0.50};
Double_t Length[3] = { 0.00, 0.50, 1.00 };
if(!initialized){
Int_t FI = TColor::CreateGradientColorTable(3,Length,Red,Green,Blue,50);
for (int i=0; i<50; i++) colors[i] = FI+i;
initialized = kTRUE;
return;
}
}
void multipalette() {
TCanvas *c3 = new TCanvas("c3","C3",0,0,600,400);
c3->Divide(2,1);
TF2 *f3 = new TF2("f3","0.1+(1-(x-2)*(x-2))*(1-(y-2)*(y-2))",1,3,1,3);
f3->SetLineWidth(1);
c3->cd(1);
f3->Draw("surf1");
TExec *ex1 = new TExec("ex1","Pal1();");
ex1->Draw();
f3->Draw("surf1 same");
c3->cd(2);
f3->Draw("surf1");
TExec *ex2 = new TExec("ex2","Pal2();");
ex2->Draw();
f3->Draw("surf1 same");
}
int Int_t
Definition RtypesCore.h:45
const Bool_t kFALSE
Definition RtypesCore.h:92
bool Bool_t
Definition RtypesCore.h:63
double Double_t
Definition RtypesCore.h:59
const Bool_t kTRUE
Definition RtypesCore.h:91
@ kBlack
Definition Rtypes.h:65
R__EXTERN TStyle * gStyle
Definition TStyle.h:412
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.)
Static function creating a color table with several connected linear gradients.
Definition TColor.cxx:2228
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
A 2-Dim function with parameters.
Definition TF2.h:29
virtual void Draw(Option_t *option="")
Draw this function with its current attributes.
Definition TF2.cxx:241
virtual void Draw(Option_t *option="")
Default Draw method for all objects.
Definition TObject.cxx:197
void SetPalette(Int_t ncolors=kBird, Int_t *colors=0, Float_t alpha=1.)
See TColor::SetPalette.
Definition TStyle.cxx:1782
return c3
Definition legend3.C:15
Author
Olivier Couet

Definition in file multipalette.C.