Automatic SetPadSideMargin based on the existing content?

Hi all,

I have a recurring issue: I need to change the default style I set in my rootlogon.C for many of my plots so that everything fits on a canvas.
The style has enlarged size of axes’ labels and titles, so they are visible when printed.
It works for a limited set of plots, however in many cases things tend to go beyond the scope of the canvas.

Here are a few examples, which typically don’t fit:

  • I want an additional top axis with its own title
  • It is a 2D colour map histogram with a colour palette labels on the right
  • The title of the bottom axis has a math fraction or subscripts

For every plot I make I re-adjust the SetPadSideMargin() of a canvas until it fits.
And I wonder if there is any code snippet existing, which would look for all existing labels/titles, etc.
And ensure that everything fits if canvas.Update() is called?

And possibly re-adjusts the margins so that everything fits within the canvas and potentially returns the Warning in the output if margins were re-adjusted?

Otherwise, it doesn’t mean a lot to say “I use a consistent style”, while every second plotting script re-adjusts this “consistent” style in order for plots to have a publishable quality look…

It has been asked before 4 years ago, and I am curious is there an update or any user-made script?

thanks!
Bohdan

Let’s see if @couet has an update on this

We are now working on an “auto” style which may cover this kind of thing.
It will be based on this doc. If your request is not in it we can add it.

1 Like

It looks very nice! Thanks for the work.

In my opinion, the following bullet can be phrased even more generally, but that’s up to debate of course.
“Make sure the canvas’s right margin is wide enough to not hide the palette title (COLZ option).”

“Make sure the canvas’s any margin is wide enough to not hide ANY user-added elements, such as titles/legends/text/lines/arrows/axes and their labels/titles

I added your point. Thanks !
If you have a few line script showing the problem that may help to implement it.

Hi @couet,

I have made a script, which produces a plot combining all the problems I could thought of.
axes_out_of_range.py (3.7 KB)
This is an obviously extreme overkill scenario.
However if “auto-style” in future could properly space this mess preserving the font size of the titles and labels and managing to fit everything inside the canvas, that would be amazing!

I obviously use the style of my collaboration, which might be slightly different for CMS/ATLAS/etc.
But I bet the other style choice won’t fix all the problems presented here.
All (or most of the) overlaps are independent and can be reproduced one-by-one, I just combined everything together for simplicity.

Cheers!

1 Like

Thanks for your example.

I added it is the doc I sent you before.

1 Like

Just thinking of another point, which I guess is a matter of convention rather than an actual issue, but still would be nice to highlight its existence.

One might want to create plots with a given ratio/size independent of the size of the labels.

When I do:
canvas = TCanvas("c", "title", 600, 600)
Somebody (me included) might expect my plots (the area inside the axes) to be a square (ratio 1:1), so each axis has an identical length when printed.

However, usually, that is not the case because left+right margins are not equal to top+bottom margins.
As a result, this compresses/stretches the plot because labels and margins are included in those 600.
So, two identical plots with slightly different labels might be stretched relative to one another.

I assume this can be corrected with:

TCanvas c = TCanvas("c", "title", 600/(1-margin.left-margin.right), 600/(1-margin.top-margin.bottom))

But this is something also might not be trivial for a beginner. Making sure the user can choose this as an option would be nice.

cheers,
Bohdan

Are you aware of this ?

1 Like

I wasn’t!
Thanks, that is useful!

EDIT: Although not quite what I wanted

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