Description
Check duplicate issues.
- Checked for duplicates
Describe the bug
When trying to draw a histogram with a transparent box on top of it, I noticed that whenever I set CanvasPreferGL
to true
, the canvas moves down, and the X-axis title is cut off.
What is the expected behaviour?
The only change I would expect is the transparency introduced to my box. Things are not supposed to be moved around only due to
gStyle->SetCanvasPreferGL(true);
How to reproduce?
Consider this macro:
void transpar()
{
gStyle->SetCanvasPreferGL(false);
TH2F *h = new TH2F("h", "h;X;Y;Z", 10, 0., 10., 10, 0., 10.);
h->Draw();
TMarker *m = new TMarker(4., 7., 8);
m->Draw();
TBox *b = new TBox(1., 1., 8., 8.);
printf("CanvasPreferGL is set to %s\n", gStyle->GetCanvasPreferGL() ? "true, the red box is expected to be transparent":"false, the red box is expected to be non-transparent");
b->SetFillColorAlpha(kRed, 0.2);
b->Draw();
}
Now if I run this as
root -l -n transpar.cxx
(no transparency is expected, so it is all good).
But when I change false
to true
at the third line
gStyle->SetCanvasPreferGL(true);
and run again
root -l -n transpar.cxx
The box is now transparent, which is good, but there is too much empty space above the histogram name (“h
”) and, as a consequence, the X-axis title is now cut off. Is there a way to make my box transparent and keep everything else where it was before?
Please note I’m using the -n
option when running transpar.cxx
, so it’s not due to something I have in my style file.
The original discussion at the ROOT forum revealed that:
- this is irreproducible if ran on local computers with Windows or Mac OS. The issue is observed only via SSH (from e.g.
lxplus7
) - in principle, the issue can be mitigated by adding the following five lines at the very end of the macro (right after
b->Draw();
; the transparency remains; the +/- 0.1 offsets need a bit of a tuning of course):
if (gStyle->GetCanvasPreferGL())
{
gPad->SetBottomMargin(gPad->GetBottomMargin() + 0.1);
gPad->SetTopMargin(gPad->GetTopMargin() - 0.1);
}
ROOT version
6.28/00
How did you install ROOT?
provided by ATLAS @ lxplus7
Which operating system are you using?
CentOS 7
Additional context
No response