Histogram title offset in pixel (and canvas margins)

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
[2] - https://root.cern.ch/root/roottalk/roottalk97/1194.html

code:
test.py (1.6 KB)

“big” plot (x 0-1):

“small” plot (x 0-0.5):

Given the way this offset is defined there is Indeed no easy way to do that.

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

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

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.

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

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

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

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.

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