Get Y-Axis Label Width?

Often when I draw histograms, the y-axis title and labels overlap each other. I know that I can call TAttAxis::SetLabelOffset() to make them so they don’t overlap, and TStyle::SetPadLeftMargin() so that the title doesn’t run off the screen. However, prior to actually drawing the histogram I don’t know what these need to be set to, because the degree of overlap depends on (among other things) the width of the y-axis labels (e.g. number-of-digits in the max label value drawn).

Instead of adjusting this manually each time I want to plot something new, I would like to have a script that can figure out ahead of time what the offsets/margins need to be for given axis title/label sizes. That way it just looks nice automatically. Is this possible? I was thinking you would have to somehow query the y-axis label width (or x-axis label height), but I don’t know how to do that. This is a problem for the col-z axis as well (extending off the pad to the right).

Ideally, it would automatically be built-in somehow … I’m using ROOT v5.34.32


A such query function is not foreseen right now.

OK. I understand that it would be difficult, it would just be nice if we didn’t have to clean up the plots by hand each time. Thanks for the response.