# TGraph set maximum number of digits not working

**URL:** <https://root-forum.cern.ch/t/tgraph-set-maximum-number-of-digits-not-working/49928>\
**Category:** Newbie\
**Created:** [May 10, 2022, 3:48pm UTC](https://root-forum.cern.ch/t/tgraph-set-maximum-number-of-digits-not-working/49928 "2022-05-10T15:48:48Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![gorsedh](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/gorsedh/32/25831_2.png) [@gorsedh](https://root-forum.cern.ch/u/gorsedh)\
**Post date:** [May 10, 2022, 3:48pm UTC](https://root-forum.cern.ch/t/tgraph-set-maximum-number-of-digits-not-working/49928/1 "2022-05-10T15:48:48Z")

</div>

Hello there,

I’m trying to draw some data but i’m having some issues with setting the maximum number of digits for the axis (for example see bottom left corner of the attached figure).  
I get this error randomly on 4 graphs, and the relevant part of the code looks like this, even if i call on the y axis g1-\>GetYaxis()-\>SetMaxDigits(2); i sometimes get axis with 3 or even more digits and this forces the y axis title out of the canvas.  
Do you know how i could either force the axis to always give me 2 digits or move the graphs on the left hand column a bit to the right in order to not have the y axis title cut in half?

Thanks in advance!

```auto
void errplot(TString channel = "pk", TString bdtCut = "0.0", TString configuration = "3.3.3.-3"){
  using namespace std;
  using namespace RooFit;
  TString pidEffs_dir = "path/";
  TString pidEffs_name = pidEffs_dir + "/pidEffs_"+ bdtCut+ "_"+configuration+".root";
  TFile *pidEffs_file = new TFile(pidEffs_name, "READ");
  int pid1 = ((TObjString *) configuration.Tokenize(".")->At(0))->String().Atoi();
  int pid2 = ((TObjString *) configuration.Tokenize(".")->At(1))->String().Atoi();
  int pid3 = ((TObjString *) configuration.Tokenize(".")->At(2))->String().Atoi();
  int pid4 = ((TObjString *) configuration.Tokenize(".")->At(3))->String().Atoi();
  float bdt = bdtCut.Atof();
  TCanvas * c = new TCanvas("c", "c", 2200, 1800);

  c->Divide(2,2);
  c->cd(1);

  ///////////////////////////////1
  //TPad c1 = new TPad();
  auto g1 = new TGraph();
  g1->SetLineWidth(0);
  g1->SetMarkerStyle(20);
  g1->SetMarkerSize(2);

  for(int pid1var:{1,3,5,7,9}){
    if(channel == "pk" ||(channel == "ppi" && pid4 <= pid1var)){
    TString currentConfiguration = Form("%s_%d.%d.%d.%d", bdtCut.Data(), pid1var, pid2, pid3, pid4);
    double sum=0;
    TString toyResFile=Form("/path/toy_%s_%s.root", channel.Data(), currentConfiguration.Data());
    TFile * file = new TFile(toyResFile, "READ");
    for(int i = 0;i<10;i++){

      TString nome_result = Form("result_0%d", i);
      auto result = (RooFitResult*)file->Get(nome_result);
      auto l = result->floatParsFinal();
      auto var = (RooRealVar*)l.at(2);
      double err = var->getError();
      sum+=err;
    }
    double mean = sum/10;
    g1->AddPoint(pid1var, mean);
    file->Close();
    }}
    if(channel == "pk"){ g1->SetTitle(";#Delta log L_{p-#pi}(p); #sigma(A_{raw}(pK))");}
  else if(channel == "ppi"){ g1->SetTitle(";#Delta log L_{p-#pi}(p); #sigma(A_{raw}(p#pi))");}
  g1->GetYaxis()->SetMaxDigits(2);
  g1->GetYaxis()->SetLabelSize(0.04);
  g1->GetXaxis()->SetLabelSize(0.04);
  g1->GetXaxis()->SetTitleSize(0.04);
  g1->GetYaxis()->SetTitleSize(0.04);

  g1->Draw();

  TString plot_name = Form("plots/plot_acperr_%s_%s_%s.pdf", channel.Data(), bdtCut.Data(), configuration.Data());
  c->SaveAs(plot_name);
}

```

_ROOT Version:_ 6.26/00  
Built for linuxx8664gcc

* * *

 ![image](https://root-forum.cern.ch/uploads/default/original/3X/c/f/cf5dc7da1d6776ba8f35bb05f1b0762886adae50.png)  
 ![image](https://root-forum.cern.ch/uploads/default/original/3X/0/0/0006a1f9820bdbc6ff94847394d18789b59b644d.png)

---

<div class="post-metadata">

**Author:** ![dastudillo](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/dastudillo/32/17280_2.png) [@dastudillo](https://root-forum.cern.ch/u/dastudillo)\
**Post date:** [May 10, 2022, 4:01pm UTC](https://root-forum.cern.ch/t/tgraph-set-maximum-number-of-digits-not-working/49928/2 "2022-05-10T16:01:53Z")

</div>

You can increase the left margin with SetLeftMargin():  
[https://root.cern/doc/master/classTAttPad.html#a52c2352a0f4d03f9875af9791d7ed965](https://root.cern/doc/master/classTAttPad.html#a52c2352a0f4d03f9875af9791d7ed965)  
e.g.

```auto
  // ...
  c->Divide(2,2);
  c->cd(1);
  gPad->SetLeftMargin(0.15);
  // ...

```

and similarly after `c->cd(3)`, otherwise 1 and 3 won’t be aligned.

---

<div class="post-metadata">

**Author:** ![gorsedh](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/gorsedh/32/25831_2.png) [@gorsedh](https://root-forum.cern.ch/u/gorsedh)\
**Post date:** [May 10, 2022, 4:08pm UTC](https://root-forum.cern.ch/t/tgraph-set-maximum-number-of-digits-not-working/49928/3 "2022-05-10T16:08:12Z")

</div>

Thank you very much, it solved my margin problem! (I don’t know if i’m allowed to mark this as the solution since the topic is about the digits problem)

---

<div class="post-metadata">

**Author:** ![dastudillo](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/dastudillo/32/17280_2.png) [@dastudillo](https://root-forum.cern.ch/u/dastudillo)\
**Post date:** [May 11, 2022, 5:07am UTC](https://root-forum.cern.ch/t/tgraph-set-maximum-number-of-digits-not-working/49928/4 "2022-05-11T05:07:15Z")

</div>

Try

```auto
  g1->GetYaxis()->SetDecimals(1);

```

instead of SetMaxDigits, so that zeroes are not stripped from labels, i.e. you’ll have 9.20 and 9.25 instead of 9.2 and 9.25, and so on.  
[https://root.cern/doc/master/classTAxis.html#a0647fea083f894bffefc41c9cc2aa34b](https://root.cern/doc/master/classTAxis.html#a0647fea083f894bffefc41c9cc2aa34b)

---

<div class="post-metadata">

**Author:** ![gorsedh](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/gorsedh/32/25831_2.png) [@gorsedh](https://root-forum.cern.ch/u/gorsedh)\
**Post date:** [May 11, 2022, 6:14am UTC](https://root-forum.cern.ch/t/tgraph-set-maximum-number-of-digits-not-working/49928/5 "2022-05-11T06:14:56Z")

</div>

I’ve tried set decimals on bottom pad and had quite the opposite effect

 ![image](https://root-forum.cern.ch/uploads/default/original/3X/9/0/905bc0d85399fab5efd66174cef395afa73b53c0.png)

---

<div class="post-metadata">

**Author:** ![couet](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/couet/32/12037_2.png) [@couet](https://root-forum.cern.ch/u/couet)\
**Post date:** [May 11, 2022, 6:38am UTC](https://root-forum.cern.ch/t/tgraph-set-maximum-number-of-digits-not-working/49928/6 "2022-05-11T06:38:20Z")

</div>

```auto
root [0] auto c = new TCanvas()
root [1] c->DrawFrame(0.5,9.,7.5,9.5)
root [2] hframe->GetYaxis()->SetDecimals(2)

```

 ![Screenshot 2022-05-11 at 08.37.08](https://root-forum.cern.ch/uploads/default/original/3X/a/3/a399ae1dbccdc20efb7e914b141fc55de29e19c5.png)

---

<div class="post-metadata">

**Author:** ![Wile\_E\_Coyote](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/wile_e_coyote/32/12417_2.png) [@Wile\_E\_Coyote](https://root-forum.cern.ch/u/Wile_E_Coyote)\
**Post date:** [May 11, 2022, 9:51am UTC](https://root-forum.cern.ch/t/tgraph-set-maximum-number-of-digits-not-working/49928/7 "2022-05-11T09:51:18Z")

</div>

@couet `c->DrawFrame(0.5, 9.0e-3, 7.5, 9.5e-3)`

---

<div class="post-metadata">

**Author:** ![couet](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/couet/32/12037_2.png) [@couet](https://root-forum.cern.ch/u/couet)\
**Post date:** [May 11, 2022, 10:43am UTC](https://root-forum.cern.ch/t/tgraph-set-maximum-number-of-digits-not-working/49928/8 "2022-05-11T10:43:14Z")

</div>

```auto
root [0] auto c = new TCanvas()
root [1] c->DrawFrame(0.5, 9.0e-3, 7.5, 9.5e-3)
root [2] hframe->GetYaxis()->SetMaxDigits(2)
root [3] hframe->GetYaxis()->SetDecimals(2)

```

 ![Screenshot 2022-05-11 at 12.42.22](https://root-forum.cern.ch/uploads/default/original/3X/9/6/9633b1d6b15e9af8ba74862afab406d2115f6c2c.png)
