Background and Foreground colors

Hi all

I am trying to make a style (using gStyle) to set background and foreground colors of histogram elements on a canvas. Lets say I want a light brown background with blue foreground (text, axis, stats, etc.).

I am trying to run this macro:

void teste()
{
  int b = 23;
  int f = 4;
  
  h = new TH1F("h","h",10,0,100);
  h->GetXaxis()->SetTitle("example X");
  h->GetYaxis()->SetTitle("example Y");
  
  gROOT->SetStyle("Modern");
  
  // background color
  gStyle->SetCanvasColor(b);
  gStyle->SetTitleFillColor(b);
  gStyle->SetStatColor(b);
  
  // foreground color
  gStyle->SetFrameLineColor(f);
  gStyle->SetGridColor(f);
  gStyle->SetStatTextColor(f);
  gStyle->SetTitleTextColor(f);
  gStyle->SetLabelColor(f,"xyz");
  gStyle->SetTitleColor(f,"xyz");
  gStyle->SetAxisColor(f,"xyz");
  
  new TCanvas();
  h->Draw();
  gPad->SetGridx();
  gPad->SetGridy();
  
}

But The axis (ticks, labels and titles) are still black. The stat border is also black. See the attached figure.

What should I do? I am running 5.30/00 on Mac OS X

Regards

Alex


A brutal fix: h->Draw(); gPad->Update(); // make sure it's really drawn h->SetAxisColor(f,"xyz"); h->SetLabelColor(f,"xyz"); h->GetXaxis()->SetTitleColor(f); h->GetYaxis()->SetTitleColor(f); ((TPaveStats*)(h->GetListOfFunctions()->FindObject("stats")))->SetLineColor(f); ((TPaveText*)(gPad->GetListOfPrimitives()->FindObject("title")))->SetLineColor(f); gPad->Update(); // make sure it's re-drawn

This works, thanks, but is there any way to use TStyle in order to get the same outcome? I do not want to do this “brute force fix” for each canvas and histogram I have to draw in one session. Defining the style I would expect that this color scheme would be applied for everything, right?

Alex

I figured out the problem. In the ROOT documentation, it states that the style of an object is configured in the momentum of its creation. In this case, I need to define the style before I create the histogram. The code below works just fine.

void teste()
{
  int b = 23;
  int f = 4;
    
  gROOT->SetStyle("Modern");
  
  // background color
  gStyle->SetCanvasColor(b);
  gStyle->SetTitleFillColor(b);
  gStyle->SetStatColor(b);
  
  // foreground color
  gStyle->SetFrameLineColor(f);
  gStyle->SetGridColor(f);
  gStyle->SetStatTextColor(f);
  gStyle->SetTitleTextColor(f);
  gStyle->SetLabelColor(f,"xyz");
  gStyle->SetTitleColor(f,"xyz");
  gStyle->SetAxisColor(f,"xyz");
  
  h = new TH1F("h","h",10,0,100);
  h->GetXaxis()->SetTitle("example X");
  h->GetYaxis()->SetTitle("example Y");
  
  new TCanvas();
  h->Draw();
  gPad->SetGridx();
  gPad->SetGridy();
}

Thanks

Alex