Order of drawing commands

Hi all,

I would like to draw some graphs/hists with some graphical objects “behind” the graphs (like shaded areas…) and some graphical objects “in front of” the graphs (like functions, TLatexs…). For both I need the user coordinate system to place the graphical objects on the right places. I tried the following approach:

hist->Draw("axis"); // To get the user coordinate system initialized // Draw objects behind graph hist->Draw("axissame"); // To repaint the axes since some graphical objects are covering the axes hist()->Draw("same"); // To get the hist/graph itself // Draw objects in front of the graph
This works quite well. The problem is that I get no histogram title drawn with this attempt. I tried various work arounds like replacing the hist->Draw(“axis”) with hist->Draw(). There I get the expected result. The problem here is that the hist is drawn twice and when saving this as ps/eps everything is saved twice and interpreted twice when reloaded with gv. So the ps/eps is also nearly twice as large and operations on the files are getting very slow for complicated graphics.

So what would be the best approach to get a graph with objects behind and other objects in front of the graph, with title and statistics box and fit functions drawn correctly?

Thanks for any hint,


Why you do not simply call

Send a short running script otherwise


Hi Rene,

In fact it is slightly more difficult. Please have a look at the attached macro. So what I would like to have is a colored region or any other graphical object that is really behind the graph. Please note also that the region can depend on the ranges of the axes (as shown in the macro).

Thanks, Mathias
drawingExample.c (1.73 KB)

You can do something like:

canvas->cd(1); Double_t uxmin = hist->GetXaxis()->GetXmin(); Double_t uxmax = hist->GetXaxis()->GetXmax(); Double_t uymin = 0.50*hist->GetMinimum(); Double_t uymax = 1.05*hist->GetMaximum(); gPad->SetTickx(); TH1 *frame = gPad->DrawFrame(uxmin, uymin, uxmax,uymax); frame->SetTitle(hist->GetTitle()); box.DrawBox(-1, uymin, 1, uymax); hist->Draw("same"); gPad->RedrawAxis(); gPad->Update();


Hi Rene,

Your solution worked except that now no statistics box is drawn any more. Nevertheless I had a try to implement a class for my own that is a subclass of TBox and represents a region of interest or a marker at the x- or y-axis. This should scale with interactive zooms and should also be clipped at the axis boundaries. I succeded in compiling the class into libgraph but when starting root I get the following message:

Anyhow I attached the .h and the .cxx files. Perhaps you will take this as “feature request” and take the class as starting point for a “Real-Root-ROI-class” :slight_smile: But take this with care, it was coded quick and dirty and is totally untested :blush:

Cheers, Mathias
TRegion.cxx (1.25 KB)
TRegion.h (676 Bytes)

I do not understand what you want to do with this class. Your class TRegion
does not add anything to TBox.


Hi Rene,

What I wanted to do is to draw kind of exclusion areas. Well, I just saw that in the newest release one can do this with TGraph via SetLineWidth. It’s not exactly what I wanted, in fact it is even better since with that you can also draw non-rectangular areas. So thanks a lot for this new feature :smiley:

Cheers, Mathias