# Histogram title offset in pixel (and canvas margins)

**URL:** <https://root-forum.cern.ch/t/histogram-title-offset-in-pixel-and-canvas-margins/26633>\
**Category:** ROOT\
**Created:** [October 21, 2017, 9:16pm UTC](https://root-forum.cern.ch/t/histogram-title-offset-in-pixel-and-canvas-margins/26633 "2017-10-21T21:16:59Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![heico](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/h/e36b37/32.png) [@heico](https://root-forum.cern.ch/u/heico)\
**Post date:** [October 21, 2017, 9:16pm UTC](https://root-forum.cern.ch/t/histogram-title-offset-in-pixel-and-canvas-margins/26633/1 "2017-10-21T21:16:59Z")

</div>

Dear experts,

I want to do a very simple thing: plot a histogram in a pad/canvas with fixed label size, label offset, title size, and title offset. Fixed here means I want to give pixel values. Reading through the documentation [1], I found the following lines:

"virtual void SetLabelOffset (Float\_t offset=0.005)  
Set distance between the axis and the labels The distance is expressed in per cent of the pad width. More…

virtual void SetLabelSize (Float\_t size=0.04)  
Set size of axis labels The size is expressed in per cent of the pad width. More…"

As I have understood this, one should therefore be able to build the pixel-sized labels and titles a la  
padvalue = pixelvalue / (pad.GetWw()\*pad.GetAbsWNDC())  
I am following what has been explained by Rene Brun in [2].

How can I also set the title offset in pixels?

I tried to do it in an anlogous way but it does not seem to work. The script you can find below as well as two plots that I have made with two different sizes of the pad “p”, done in line 32. Once, I have x in the range 0-1, this is the “big” plot, and once i have x in the range 0-0.5 resulting in the plot denoted “small”, while y always is in the range 0-1. As you see, the x and y titles have different offsets, so I must be missing some term or in general not do it properly…

EDIT: actually, also x axis label offset seems to be different for the two plots.

Margins seem OK but I guess its because they are defined on the canvas rather than the pad.

Thank you for any useful advice!  
heico

PS: for the canvas margins I have also tried the following construction:  
c.SetXXXMargin(c.PixeltoYYY(ZZZ)) where XXX=(Top,Bottom,Left,Right), YYY=(X for Left/Right and Y for Top/Bottom), ZZZ=the different values as given in the file  
This has worked fine for Left and Right (PixeltoX) but PixeltoY always has returned 0.1 for whatever value I have entered!  
I’m using ROOT v6.08 on MacOSX 10.12.16.

[1] - [https://root.cern.ch/doc/master/classTAttAxis.html](https://root.cern.ch/doc/master/classTAttAxis.html)  
[2] - [https://root.cern.ch/root/roottalk/roottalk97/1194.html](https://root.cern.ch/root/roottalk/roottalk97/1194.html)

code:  
[test.py](https://root-forum.cern.ch/uploads/default/original/2X/2/2d0b58274d91d60d9e3b1a30233d0fcb56995de2.py) (1.6 KB)

“big” plot (x 0-1):

 ![big](https://root-forum.cern.ch/uploads/default/original/2X/6/65092ade790d1823019c50496ab2246fe61897f8.png)

“small” plot (x 0-0.5):

 ![small](https://root-forum.cern.ch/uploads/default/original/2X/a/a6d9fa754956f8634cb3d85b3aa72f0110833318.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:** [October 23, 2017, 11:16am UTC](https://root-forum.cern.ch/t/histogram-title-offset-in-pixel-and-canvas-margins/26633/3 "2017-10-23T11:16:43Z")

</div>

> [@heico](#):
>
> How can I also set the title offset in pixels?

Given [the way this offset is defined](https://root.cern/doc/master/classTAttAxis.html#a3ea231f2b403734c253597bc1b23c82d) there is Indeed no easy way to do that.

---

<div class="post-metadata">

**Author:** ![heico](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/h/e36b37/32.png) [@heico](https://root-forum.cern.ch/u/heico)\
**Post date:** [October 23, 2017, 4:54pm UTC](https://root-forum.cern.ch/t/histogram-title-offset-in-pixel-and-canvas-margins/26633/4 "2017-10-23T16:54:55Z")

</div>

Dear couet,

Thank you for the reply. I will probably have to play around with math a bit.  
How is the nominal value of the title offset computed?

What about the label offset which seemingly is affected by the pad width though it shouldn’t be?

Thank you,  
heico

---

<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:** [October 24, 2017, 7:31am UTC](https://root-forum.cern.ch/t/histogram-title-offset-in-pixel-and-canvas-margins/26633/5 "2017-10-24T07:31:46Z")

</div>

> [@heico](#):
>
> How is the nominal value of the title offset computed?

It is computed at the end of `TGAxis::PaintAxis()`

> [@heico](#):
>
> What about the label offset which seemingly is affected by the pad width though it shouldn’t be?

As said in the doc the label offset definition is: The distance between the axis and the labels The distance is expressed in per cent of the pad width.

---

<div class="post-metadata">

**Author:** ![heico](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/h/e36b37/32.png) [@heico](https://root-forum.cern.ch/u/heico)\
**Post date:** [October 24, 2017, 10:14am UTC](https://root-forum.cern.ch/t/histogram-title-offset-in-pixel-and-canvas-margins/26633/6 "2017-10-24T10:14:37Z")

</div>

> [@couet](#):
>
> It is computed at the end of TGAxis::PaintAxis()

Thanks. Looking at the code it seems quite nonlinear, maybe I’ll find a way to implement it.

> [@couet](#):
>
> As said in the doc the label offset definition is: The distance between the axis and the labels The distance is expressed in per cent of the pad width.

As I wrote in my original post, I am using the expression

```auto
padvalue = pixelvalue / (pad.GetWw()*pad.GetAbsWNDC())

```

to compute the padvalue from the pixel value correcting for the reduced pad width.  
Since you haven’t disconfirmed this expression, I assume it should work to have the SAME label offset for x and y axes in both of the plots but as you can clearly see, only for the y axis the label offset stays the same while for the x axis the label offset is increased and therefore NOT following this logic. Is the expression wrong, does my script have a bug, or is there some other sort of computation involved? Looking at the PaintAxis function line 1254 and beyond it seems OK to me on first sight, so I’m a bit puzzled seeing this behavior!

heico

---

<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:** [October 24, 2017, 10:59am UTC](https://root-forum.cern.ch/t/histogram-title-offset-in-pixel-and-canvas-margins/26633/7 "2017-10-24T10:59:36Z")

</div>

I am not sure this conversion to pixel is really feasible as TGaxis offers are all defined relatively to the axis length, pad width and also depends on the size of the characters used to draw the labels and titles.

---

<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:** [November 7, 2017, 10:59am UTC](https://root-forum.cern.ch/t/histogram-title-offset-in-pixel-and-canvas-margins/26633/8 "2017-11-07T10:59:51Z")

</div>

Closed on November 7, 2017, 10:59am UTC

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