Remove TCanvas border

how to remove the canavs border when the margins are small ?

Hi,

Could you share all the info to reproduce the behaviour (platform, root version, minimal code snippet…)?

Cheers,
D

The border you get is not a “Canvas border” but that’s the frame limits which appear to be close to the Canvas edges as your margins are small. You can remove it with canvas->SetFrameLineWidth(0);

It’s not the frame that’s the problem, adding this line produces the following situation where the top and right boundaries of the plot disappear but at the bottom and on the right the black boundary persists. I’ll work on producing a MWE that reproduces the issue

In that case it is clear to me which border you are talking about. Can you provide a small example reproducing your problem ?

here’s a mwe:

void MWE()
{
  TH1D *h = new TH1D("h","",100,-1,1);
  for (Int_t i = 0; i < 1000000; i++) h->Fill(gRandom->Gaus(0, 1));

  TCanvas *c = new TCanvas("c","c",900,700);
  h->Draw();
  c->SetLogy();
  c->SetMargin(0.071, 0.0044, 0.08, 0.019);
  c->SetBorderSize(0);
  c->Update();

  c->SaveAs("mwe.png");
}

It gives this, where you can see on the right and at the bottom a black kind of bevel border.

I think it doesn’t happen in the pdf (uploaded below)
mwe.pdf (14.1 KB)

Thanks I will check.

try:

root -b mwe.C

This works but the resolution is very low

Make A bigger canvas.
Without -b option the png file is generated using a screen dump of the displayed bitmap. It looks like so black line are added in that case. Note sure by whom because they do not show in PDF and PS and not when using batch mode . I batch mode TASImage is used.

ok thank you

You can also increase the definition using:

      gStyle->SetImageScaling(3.);

This isn’t a great solution either, now all the black lines are almost invisible

{
  Int_t ci = TColor::GetFreeColorIndex();
  TColor* my_col;
  double colours[][3] =
    {
      {0.3647, 0.6588, 0.6000},//index 0
      {0.1803, 0.1451, 0.5216},//index 1     
	};
  
  my_col = new TColor(ci, colours[index][0], colours[index][1], colours[index][2]);
  return ci;
}

void MWE()
{
  gStyle->SetImageScaling(10.);
  
  TH1D *h1 = new TH1D("h1","",100,-1,1);
  TH1D *h2 = new TH1D("h2","",100,-1,1);
  TH1D *h3 = new TH1D("h3","",100,-1,1);

  THStack* stack = new THStack("stack","");
  stack->Add(h2);
  stack->Add(h3);

  h2->SetFillColor(histo_colours(0));
  h3->SetFillColor(histo_colours(1));

  TLegend* legend = new TLegend(0.548, 0.606, 0.996, 0.9765);
  legend->SetTextSize(0.042);
  legend->SetNColumns(2);

  legend->AddEntry(h1,"h1");
  legend->AddEntry(h1,"h2");
  legend->AddEntry(h1,"h2");
  
  for (Int_t i = 0; i < 1000000; i++)
    {
      h1->Fill(gRandom->Gaus(0, 1));
      h2->Fill(gRandom->Gaus(0, 1));
      h3->Fill(gRandom->Gaus(0, 1));
    }
  
  TCanvas *c = new TCanvas("c","c",900,700);
  TRatioPlot* rp = new TRatioPlot(stack,h1);
 
  rp->Draw();
  rp->GetUpperPad()->cd();
  
  h1->Draw("AE");
  stack->Draw("SAME HIST");
  legend->Draw();
  h1->Draw("SAMEE");

  c->SetLogy();
  c->SetMargin(0.071, 0.0044, 0.08, 0.019);
  c->SetBorderSize(0);
  c->Update();

  c->SaveAs("mwe.png");
}

Reduce it, 10 is to much. I suggested 3.
It is what we are using to generate the images of the reference guide:
https://root.cern/doc/master/graph_8C.html

It’s not the best solution since the black in any case becomes grey and the fonts change running in batch mode. Between the two options I’d prefer to stick with the annoying black lines

I would recommend you to use vector graphics outpout like pdf files.

Since you don’t give details of your setup it’s hard to tell, and running your mwe I don’t see the issue either on linux (*ubuntu) or windows (Ubuntu on WSL), so it seems to be a particular problem on your system. Some things you can try:

  • use a more recent version of ROOT
  • install all the dependencies for ROOT for your system (Dependencies - ROOT); even if you think you already did it, do it again --if they were already installed this doesn’t hurt
  • also install / update libgif-dev and libpng-dev

Fair comment, I’m working on macos, root 6.32. If what I read on stackeoverflow is right, i should have c++ 16 not 17?

gcc -dumpversion | cut -f1,2,3 -d.

16.0.0

I installed root using homebrew so i’m surprised it didn’t automatically install the correct versions of the dependencies.
I also haven’t updated xcode since i’ve seen the current version of root isn’t compatible with the latest version of xcode

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.