Using setpalette for 2 canvases

Hi,

I want to plot 2 separate 2D histograms from the same large dataset, but I need to have different palettes for the 2 plots. I’m sending them to different canvases/pads, but when I use:
c1->cd();
gStyle->SetPalette( xxx );
hist1->UseCurrentStyle();
hist1->DrawCopy(“colz”);
c2->cd();
gStyle->SetPalette( yyy );
hist2->UseCurrentStyle();
hist2->DrawCopy(“colz”);
the 2 plots come out with the same colour scheme. I’ve tried using gPad->Update; gPad->Modified after each draw command, but this doesn’t help. Is there any way to use 2 colour schemes in the same macro?

Cheers

you can extrapolate from the example below

Rene

{ TCanvas *c1 = new TCanvas("c1"); TH2F *h1 = new TH2F("h1","h1",40,-4,4,40,-4,4); TH2F *h2 = new TH2F("h2","h2",40,-4,4,40,-4,4); Double_t a,b; for (Int_t i=0;i<5000;i++) { gRandom->Rannor(a,b); h1->Fill(a-1.5,b-1.5); h2->Fill(a+1.5,b+1.5); } TExec *ex1 = new TExec("ex1","gStyle->SetPalette(0);"); TExec *ex2 = new TExec("ex2","gStyle->SetPalette(1);"); h1->Draw("colz"); ex1->Draw(); h1->Draw("col same"); ex2->Draw(); h2->Draw("col same"); }

But then if the palette I want to set is a custom one I need to assign this to one of the default palette settings … what is the best way of doing this?

ah, being stupid about sprintf with arrays, it works now, thanks!

I suggest the following: Put the code below into the file “towpal.C” and you will get the attached image when you will execute it.

void twopal()
{
   TCanvas *c1 = new TCanvas("c1");
   TH2F *h1 = new TH2F("h1","h1",40,-4,4,40,-4,4);
   TH2F *h2 = new TH2F("h2","h2",40,-4,4,40,-4,4);
   Double_t a,b;
   for (Int_t i=0;i<5000;i++) {
   gRandom->Rannor(a,b);
   h1->Fill(a-1.5,b-1.5);
   h2->Fill(a+1.5,b+1.5);
   }
   TExec *ex1 = new TExec("ex1","grey();");
   TExec *ex2 = new TExec("ex2","gStyle->SetPalette(1);");
   h1->Draw("colz");
   ex1->Draw();
   h1->Draw("col same");
   ex2->Draw();
   h2->Draw("col same");
}

void grey()
{
   Double_t Red[2]   = { 0.00, 1.00};
   Double_t Green[2] = { 0.00, 1.00};
   Double_t Blue[2]  = { 0.00, 1.00};
   Double_t Stops[2] = { 0.00, 1.00};

   Int_t nb=50;
   TColor::CreateGradientColorTable(2,Stops,Red,Green,Blue,nb);
}