Logo ROOT  
Reference Guide
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);
f3->SetLineColor(kBlack);
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");
}
Author
Olivier Couet

Definition in file multipalette.C.

kTRUE
const Bool_t kTRUE
Definition: RtypesCore.h:91
c3
return c3
Definition: legend3.C:15
colors
Color * colors
Definition: X3DBuffer.c:21
TStyle.h
Int_t
int Int_t
Definition: RtypesCore.h:45
TColor.h
TCanvas.h
Bool_t
bool Bool_t
Definition: RtypesCore.h:63
TExec
Definition: TExec.h:28
kBlack
@ kBlack
Definition: Rtypes.h:65
TF2.h
gStyle
R__EXTERN TStyle * gStyle
Definition: TStyle.h:412
kFALSE
const Bool_t kFALSE
Definition: RtypesCore.h:92
TF2::Draw
virtual void Draw(Option_t *option="")
Draw this function with its current attributes.
Definition: TF2.cxx:241
TF2
Definition: TF2.h:29
TExec.h
TObject::Draw
virtual void Draw(Option_t *option="")
Default Draw method for all objects.
Definition: TObject.cxx:197
Double_t
double Double_t
Definition: RtypesCore.h:59
TStyle::SetPalette
void SetPalette(Int_t ncolors=kBird, Int_t *colors=0, Float_t alpha=1.)
See TColor::SetPalette.
Definition: TStyle.cxx:1785
TCanvas
Definition: TCanvas.h:23
TColor::CreateGradientColorTable
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:2225