TCanvas frame showing

I’m creating some histograms and I want to minimise the margins so that they don’t have to be trimmed later. I have the following style function:

void PlotAesthetics::TH1Style(TH1* hHisto, TCanvas* canv, bool StatsBox)
{  
gStyle->SetMarkerColor(kBlue);
gStyle->SetMarkerStyle(8);
gStyle->SetMarkerSize(0.8);
  
gStyle->SetPadRightMargin(0.005);
gStyle->SetPadBottomMargin(0.11);
gStyle->SetPadTopMargin(0.01);

gStyle->SetTitleOffset(1.4, "Y");
gStyle->SetTitleOffset(1.2, "X");
  if(StatsBox==false)
    gStyle->SetOptStat(0);
  else
    {
      double yMax = hHisto->GetMaximum();
      yMax *= 1.1;
      hHisto->SetMaximum(yMax);

      TPaveStats* spStats = (TPaveStats*)hHisto->FindObject("stats");
      spStats->SetOptStat(1111111);
    }
  
  if(hHisto->GetMaximum()>=1&&hHisto->GetMaximum()<10)
    {
      gStyle->SetPadLeftMargin(0.08);
      gStyle->SetTitleOffset(1.1, "Y");
    }
  if(hHisto->GetMaximum()>=0.1&&hHisto->GetMaximum()<1)
    {
      //
    }
  if(hHisto->GetMaximum()>=0.01&&hHisto->GetMaximum()<0.1)
    {
      gStyle->SetPadLeftMargin(0.2);
      gStyle->SetTitleOffset(1.6, "Y");
    }
  canv->SetBorderMode(0);
  canv->SetBorderSize(0);

  canv->UseCurrentStyle();
}

But in the third if() case, the plot produced looks like this:


How do I get rid of the border on the left hand side?
Thanks in advance

@couet Can you help with this?

yes. looking at it

Try:

gStyle->SetPadLeftMargin(0.02); // 0.02 instead of 0.2

Maybe one also needs:

canv->UseCurrentStyle();
canv->Modified(); canv->Update(); // make sure it's redrawn
1 Like

I guess @Wile_E_Coyote will fix the issue. BTW I tried to reproduce it with the following code and the problem does not show:

{
   gStyle->SetPadRightMargin(0.005);
   gStyle->SetPadBottomMargin(0.11);
   gStyle->SetPadTopMargin(0.01);
   gStyle->SetPadLeftMargin(0.2);

   gStyle->SetTitleOffset(1.4, "Y");
   gStyle->SetTitleOffset(1.2, "X");
   gStyle->SetOptStat(0);

   auto canv = new TCanvas();
   canv->SetBorderMode(0);
   canv->SetBorderSize(0);

   canv->UseCurrentStyle();
   TH1F *hr =  canv->DrawFrame(-4.,-4,4.,4);
   hr->SetTitle(";aaa;bbb")
}

Thank you, ensuring the canvas is redrawn works

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