How set the color of the margin

Hi All,

I got a problem when I use “TCanvas::SetBottomMargin”, the resulting plot gives additinal black boundary. I wonder how can I get rid of it.

The relavent code is:

  TString FinalCanvasName = rootfolder + "MyCanvas" ;
  TCanvas *FinalCanvas = new TCanvas("FinalCanvasName", "Combination");
  TPostScript *FinalFigure= new TPostScript(figurename,112);
  cout<<"cccccccccccccccccc"<<endl;
  FinalCanvas->Divide(1,1);
//  FinalCanvas->SetLogy();
  FinalCanvas->cd();
//  hist_bg_TT_Zh_ll->Draw();
//  hist_bg_Zhf->Draw();
  hist_stack->Draw();
  leg->Draw("same");
  cout<<"cccccccccccccccccc"<<endl;
  hist_stack->GetHistogram()->GetXaxis()->SetTitle("m_{h_{heavy}}^{rec}  [GeV]");
  hist_stack->GetHistogram()->GetXaxis()->SetTitleSize(0.05);
  hist_stack->GetHistogram()->GetXaxis()->SetTitleOffset(1.20);
  hist_stack->GetHistogram()->GetXaxis()->SetLabelSize(0.05);
  hist_stack->GetHistogram()->SetTitle("m_{h_{heavy}}^{rec}");
//  cout<<"cccccccccccccccccc"<<endl;
  hist_stack->GetYaxis()->SetTitle("Events/8GeV");
  hist_stack->GetYaxis()->SetTitleSize(0.05);
  hist_stack->GetYaxis()->SetLabelSize(0.05);
  hist_stack->GetHistogram()->GetYaxis()->SetTitleOffset(1.20);
  hist_stack->GetHistogram()->GetYaxis()->SetLabelSize(0.05);
  FinalCanvas->SetBottomMargin(0.20);
  FinalCanvas->SetLeftMargin(0.15);
 // hist_stack.GetYaxis()->(100,10000);
 // hist_bg_dibosons_llbb->Draw();
//  hist_bg_SM_Zh_ll->Draw();
  cout<<hist_signal_llbb->Integral()<<endl;
  FinalCanvas->Update();
//  FinalCanvas->Print("mllbb.pdf","pdf");
  FinalFigure->Close();
  delete FinalCanvas;
  delete leg;


Can you post a script we could run which reproduces this issue ?
Thanks.

[quote=“couet”]Can you post a script we could run which reproduces this issue ?
Thanks.[/quote]

the following code does:

	filename = "test.eps";
	TH1 *h1 = new TH1F("h1","h1",50,-3,3);
	TH1 *h2 = new TH1F("h2","h2",50,-3,3);
	h1->FillRandom("gaus",10000);
	h2->FillRandom("gaus",3000);
	THStack *hs = new THStack("hs","hs");
	h1->SetFillColor(2);
	h1->SetLineWidth(0);
	h2->SetFillColor(5);
	h2->SetLineWidth(0);
	hs->Add(h1);
	hs->Add(h2);
	TCanvas *c = new TCanvas("c","c");
	TPostScript *fig = new TPostScript(filename,112);
	c->cd();
	hs->Draw();
	hs->GetHistogram()->GetXaxis()->SetTitle("h1");
	hs->GetHistogram()->GetXaxis()->SetTitleSize(0.05);
	hs->GetHistogram()->GetXaxis()->SetTitleOffset(1.20);
	hs->GetHistogram()->GetXaxis()->SetLabelSize(0.05);
	hs->GetHistogram()->GetYaxis()->SetTitle("a.u.");
	hs->GetHistogram()->GetYaxis()->SetTitleSize(0.05);
	hs->GetHistogram()->GetYaxis()->SetTitleOffset(1.20);
	hs->GetHistogram()->GetYaxis()->SetLabelSize(0.05);
	c->SetBottomMargin(0.2);
	c->SetLeftMargin(0.15);
	c->Update();
	fig->Close();
	delete c;
	delete fig;
	delete h1;
	delete h2;
	delete hs;

are is a working version of your macro:

{
   filename = "test.eps";
   TH1 *h1 = new TH1F("h1","h1",50,-3,3);
   TH1 *h2 = new TH1F("h2","h2",50,-3,3);
   h1->FillRandom("gaus",10000);
   h2->FillRandom("gaus",3000);
   THStack *hs = new THStack("hs","hs");
   h1->SetFillColor(2);
   h1->SetLineWidth(0);
   h2->SetFillColor(5);
   h2->SetLineWidth(0);
   hs->Add(h1);
   hs->Add(h2);
   TCanvas *c = new TCanvas("c","c");
   c->SetBottomMargin(0.2);
   c->SetLeftMargin(0.15);
   TPostScript *fig = new TPostScript(filename,112);
   c->cd();
   hs->Draw();
   hs->GetHistogram()->GetXaxis()->SetTitle("h1");
   hs->GetHistogram()->GetXaxis()->SetTitleSize(0.05);
   hs->GetHistogram()->GetXaxis()->SetTitleOffset(1.20);
   hs->GetHistogram()->GetXaxis()->SetLabelSize(0.05);
   hs->GetHistogram()->GetYaxis()->SetTitle("a.u.");
   hs->GetHistogram()->GetYaxis()->SetTitleSize(0.05);
   hs->GetHistogram()->GetYaxis()->SetTitleOffset(1.20);
   hs->GetHistogram()->GetYaxis()->SetLabelSize(0.05);
   fig->Close();
   delete c;
   delete fig;
   delete h1;
   delete h2;
   delete hs;
}

Yes, thank you very much! Would you mind telling me the reason such changes works so that I can avoid similar problems in the future. Really appreciate.

By the way, I really wanna to mater ROOT, since it has so many great featrues. But there always some buggy point that I am hard to find out, do you have any advices for learning ROOT more efficiently?

[quote=“couet”]are is a working version of your macro:

{ filename = "test.eps"; TH1 *h1 = new TH1F("h1","h1",50,-3,3); TH1 *h2 = new TH1F("h2","h2",50,-3,3); h1->FillRandom("gaus",10000); h2->FillRandom("gaus",3000); THStack *hs = new THStack("hs","hs"); h1->SetFillColor(2); h1->SetLineWidth(0); h2->SetFillColor(5); h2->SetLineWidth(0); hs->Add(h1); hs->Add(h2); TCanvas *c = new TCanvas("c","c"); c->SetBottomMargin(0.2); c->SetLeftMargin(0.15); TPostScript *fig = new TPostScript(filename,112); c->cd(); hs->Draw(); hs->GetHistogram()->GetXaxis()->SetTitle("h1"); hs->GetHistogram()->GetXaxis()->SetTitleSize(0.05); hs->GetHistogram()->GetXaxis()->SetTitleOffset(1.20); hs->GetHistogram()->GetXaxis()->SetLabelSize(0.05); hs->GetHistogram()->GetYaxis()->SetTitle("a.u."); hs->GetHistogram()->GetYaxis()->SetTitleSize(0.05); hs->GetHistogram()->GetYaxis()->SetTitleOffset(1.20); hs->GetHistogram()->GetYaxis()->SetLabelSize(0.05); fig->Close(); delete c; delete fig; delete h1; delete h2; delete hs; } [/quote]

To define properly the pad geometry ROOT needs to know all the margins’ values before drawing the pad.
That’s why they have to be set before.

Yes ROOT is complex and I need the doc also … I guess a good start is to use the tutorials which cover quite a lot of the ROOT features. root.cern/doc/master/group__Tutorials.html