# Set histo title offset

**URL:** <https://root-forum.cern.ch/t/set-histo-title-offset/58869>\
**Category:** ROOT\
**Created:** [April 5, 2024, 1:27pm UTC](https://root-forum.cern.ch/t/set-histo-title-offset/58869 "2024-04-05T13:27:26Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![bethlong06](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/bethlong06/32/22982_2.png) [@bethlong06](https://root-forum.cern.ch/u/bethlong06)\
**Post date:** [April 5, 2024, 1:27pm UTC](https://root-forum.cern.ch/t/set-histo-title-offset/58869/1 "2024-04-05T13:27:26Z")

</div>

I have a canvas of 16 different histograms and for some reason their titles are being drawn on top of the pads. How can I move them up so that they don’t cover the plot?  
Thanks

 ![image](https://root-forum.cern.ch/uploads/default/original/3X/0/8/085363b11921a662e55bb8b4d699bd3cf1f0d29f.jpeg)

---

<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:** [April 5, 2024, 1:43pm UTC](https://root-forum.cern.ch/t/set-histo-title-offset/58869/2 "2024-04-05T13:43:17Z")

</div>

```auto
{
   TH1F *h1= new TH1F("h1","histogram 1",100,-5,5);
   h1->FillRandom("gaus",10000);
   h1->Draw();
   gPad->Update();
   TPaveText* title = (TPaveText*)gPad->FindObject("title");
   title->SetY1NDC(0.5);
   title->SetY2NDC(0.6);
   gPad->Modified();
   gPad->Update();
}

```

---

<div class="post-metadata">

**Author:** ![bethlong06](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/bethlong06/32/22982_2.png) [@bethlong06](https://root-forum.cern.ch/u/bethlong06)\
**Post date:** [April 5, 2024, 2:14pm UTC](https://root-forum.cern.ch/t/set-histo-title-offset/58869/3 "2024-04-05T14:14:54Z")

</div>

The only problem is I’m using pyroot, I tried

```auto
title = gPad.FindObject("title")

```

but this gives me the error:

```auto
title.SetY1NDC(0.5)
    ^^^^^^^^^^^^^^
AttributeError: 'TObject' object has no attribute 'SetY1NDC'

```

so I tried:

```auto
title = TPaveText(gPad.FindObject("title"))

```

but I got

```auto
TypeError: none of the 3 overloaded methods succeeded. Full details:
  TPaveText::TPaveText(const TPaveText& pavetext) =>
    TypeError: could not convert argument 1
  TPaveText::TPaveText() =>
    TypeError: takes at most 0 arguments (1 given)
  TPaveText::TPaveText(double x1, double y1, double x2, double y2, const char* option = "br") =>
    TypeError: takes at least 4 arguments (1 given)

```

---

<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:** [April 5, 2024, 2:51pm UTC](https://root-forum.cern.ch/t/set-histo-title-offset/58869/4 "2024-04-05T14:51:17Z")

</div>

An other way:

```auto
void titlepos(){
   TH1F *h1= new TH1F("h1","histogram 1",100,-5,5);
   h1->FillRandom("gaus",10000);
   gStyle->SetTitleX(0.3);
   gStyle->SetTitleY(0.5);
   h1->Draw();
}

```

---

<div class="post-metadata">

**Author:** ![bethlong06](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/bethlong06/32/22982_2.png) [@bethlong06](https://root-forum.cern.ch/u/bethlong06)\
**Post date:** [April 5, 2024, 4:40pm UTC](https://root-forum.cern.ch/t/set-histo-title-offset/58869/5 "2024-04-05T16:40:06Z")

</div>

This works but as soon as the title is just above the plot it gets covered by the pad above

```auto
for i_plot in range(16):
    canvas_x_channels.cd(i_plot+1)
    x_temp_list = [sublist[i_plot] for sublist in analogues_x]
    [x_histo.Draw("same") for x_histo in x_temp_list]
    x_temp_list[0].SetTitle(f"x_channel{x_channels[i_plot]}")
    gStyle.SetTitleX(0.3);
    gStyle.SetTitleY(1.02)

```

![image](https://root-forum.cern.ch/uploads/default/original/3X/c/c/cc44f8027443e1e748b00217d941321cb304198a.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:** [April 8, 2024, 7:50am UTC](https://root-forum.cern.ch/t/set-histo-title-offset/58869/6 "2024-04-08T07:50:30Z")

</div>

> [@bethlong06](#):
>
> gets covered by the pad above

It means your pads overlap… avoid that.

---

<div class="post-metadata">

**Author:** ![bethlong06](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/bethlong06/32/22982_2.png) [@bethlong06](https://root-forum.cern.ch/u/bethlong06)\
**Post date:** [April 10, 2024, 12:57pm UTC](https://root-forum.cern.ch/t/set-histo-title-offset/58869/7 "2024-04-10T12:57:38Z")

</div>

How do I avoid that? My pads are created like this:

```auto
my_canv = ROOT.TCanvas("my_canv ","my_canv ",1800,1400)
my_canv .Divide(4,4)

```

---

<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:** [April 10, 2024, 1:10pm UTC](https://root-forum.cern.ch/t/set-histo-title-offset/58869/8 "2024-04-10T13:10:36Z")

</div>

Well , I do not know enough of your case to know what should be change. I can try to reproduce it with he follwoing code. But it is fine for me:

```auto
{
   auto c1 = new TCanvas("c1","multipads",1800,1400);
   gStyle->SetOptStat(0);
   c1->Divide(2,2);
   auto h1 = new TH2F("h1","test1",10,0,1,20,0,20);
   auto h2 = new TH2F("h2","test2",10,0,1,20,0,100);
   auto h3 = new TH2F("h3","test3",10,0,1,20,-1,1);
   auto h4 = new TH2F("h4","test4",10,0,1,20,0,1000);

   c1->cd(1);
   h1->Draw();

   c1->cd(2);
   h2->Draw();

   c1->cd(3);
   h3->Draw();

   c1->cd(4);
   h4->Draw();
}

```

---

<div class="post-metadata">

**Author:** ![bethlong06](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/bethlong06/32/22982_2.png) [@bethlong06](https://root-forum.cern.ch/u/bethlong06)\
**Post date:** [April 10, 2024, 6:57pm UTC](https://root-forum.cern.ch/t/set-histo-title-offset/58869/9 "2024-04-10T18:57:38Z")

</div>

Ok, thank you, it seems that my PadTopMargin was too small.

---

<div class="post-metadata">

**Author:** ![system](https://root-forum.cern.ch/uploads/default/original/3X/e/f/efe4f24398fd8ffeb76bccb6ecc46d9d9c003376.png) [@system](https://root-forum.cern.ch/u/system)\
**Post date:** [April 24, 2024, 6:57pm UTC](https://root-forum.cern.ch/t/set-histo-title-offset/58869/10 "2024-04-24T18:57:47Z")

</div>

Closed on April 24, 2024, 6:57pm UTC

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