[ROOT-5241] Hardcoded background fill in THStack::Paint Created: 05/Jun/13  Updated: 03/Dec/13  Resolved: 03/Dec/13

Status: Closed
Project: ROOT
Component/s: Graphics
Affects Version/s: 5.34/00
Fix Version/s: None

Type: Bug Priority: Medium
Reporter: Noel Dawe (Inactive) Assignee: Olivier Couet
Resolution: Fixed Votes: 1
Labels: None


Planned Start:
Planned End:


Hello ROOT developers...

Here is a long-standing problem with how THStacks are painted:


In THStack::Paint the bottom histogram is hardcoded to have a filled background so it is impossible to overlay THStacks with all histograms having a hollow (or hatched) fill.

It amazes me this is still a problem!

I easily get the correct output when commenting out two lines in THStack.cxx:

800          if (i>0) {                                                             
801             // Erase before drawing the histogram                               
802             h1col  = h1->GetFillColor();                                        
803             h1fill = h1->GetFillStyle();                                        
804             //h1->SetFillColor(10);                             <==== this line                
805             //h1->SetFillStyle(1001);                           <==== and this one...                
806             h1->Paint(loption);                                                 
807             static TClassRef clTFrame = TClass::GetClass("TFrame",kFALSE);      
808             TAttFill *frameFill = (TAttFill*)clTFrame->DynamicCast(TAttFill::Class(),gPad->GetFrame());
809             if (frameFill) {                                                    
810                h1->SetFillColor(frameFill->GetFillColor());                     
811                h1->SetFillStyle(frameFill->GetFillStyle());

Comment by Olivier Couet [ 10/Jun/13 ]

As you can see the comment says: "Erase before drawing the histogram"
So this code you commented is really there on purpose to do exactly that.
If you comment it blindly that way I am afraid this will produce some
unwanted side effects for some other users.

Comment by Noel Dawe (Inactive) [ 13/Jun/13 ]

Uhm... what is the intended behaviour then? What is meant by "erase before drawing the histogram"?

I think it is pretty clear that forcing a fill on the bottom histogram is not desired. Read the thread linked above.

Comment by Olivier Couet [ 13/Jun/13 ]

As I said this was done on purpose 8 years ago:
For sure we can remove this code... but then the reason why
it was introduced will show up again... Do we take the risk ?

Comment by Peter Waller (Inactive) [ 13/Jun/13 ]

Hi Olivier, it's not clear to me what the reasons are for forcing this - from everything I've read (along with the commit message). Surely the current case will continue to be possible, but forcing it seems to break a very useful case and it is hard to see from here what the other use case is.

Can you please make clearer why it was added?

Comment by Olivier Couet [ 14/Jun/13 ]

Hi Peter,
As I pointed this was done 8 years ago. The only track we have is this
svn log. I am afraid the reason why it was done that way has been lost.
May be the best will be to try to do it as you want, run some examples
I have and if they look fine just go for it and take the risk to have
some side effects ... I do not see other way ....

Comment by Noel Dawe (Inactive) [ 17/Jun/13 ]

I think this commit must have been a "temporary" hack to workaround the fact that THStack::Paint doesn't define the filled area properly.

This is what ROOT currently provides:


Clearly not ideal; the bottom histograms are hardcoded to have a filled background, covering what is below.

After commenting out the lines mentioned in the original report above this is what I get:


which is better but it exposes a problem with how THStack::Paint defines the regions to be filled and sheds some light on why Rene would have made this change:


THStack::Paint seems to be filling between the top of each histogram and the x-axis instead of between the tops of histograms. This is clear from:


where you can see the hatches intersecting in the bottom two histograms of the stack.

So, the solution seems rather simple to me: fix THStack::Paint so that it only fills between the top of a histogram and the top of the histogram beneath it. Then the user can control the fills/styles of each histogram in the stack as he/she wishes. No need for this ugly hack which seems to only create OK results when the stack happens to not have anything under it.

By the way, matplotlib does this correctly since they use a "fill_between" function to create patches with boundaries defined by the tops of adjacent histograms.

Comment by Olivier Couet [ 08/Jul/13 ]

So, the solution seems rather simple to me: fix THStack::Paint so that it only fills between the top of a histogram and the top of the histogram beneath it.

Seems to me what is done now is equivalent to that.

Comment by Noel Dawe (Inactive) [ 08/Jul/13 ]

@Olivier that can't be the case, because the hatch lines are overlapping in http://i.imgur.com/M5OsY1j.png

Comment by Olivier Couet [ 08/Jul/13 ]

If you fill only the the space between the histograms, as you suggested, then the hatches do not overlap anymore then that's equivalent of what we are doing now.

Comment by Noel Dawe (Inactive) [ 08/Jul/13 ]

Maybe these two figures will help clarify.

This is what I get with ROOT after hacking the source by commenting out the lines that force a white fill on the bottom histograms:


This is the desired result using rootpy [1] and matplotlib [2]:


Notice that the histogram areas are only filled between the tops of adjacent histograms in the stack.

Is this behaviour possible with ROOT?

The fact that ROOT forces a white fill on the bottom two histograms is already a problem, but as I say above, I think this was done to prevent the hatches from crossing and appear as though the areas are only filled between adjacent tops. Forcing a white fill is definitely not desirable when plotting on top of something else that should be visible through the stack.

[1] https://github.com/rootpy/rootpy
[2] http://matplotlib.org/

Comment by Olivier Couet [ 08/Jul/13 ]

But your pink solid histo in not part of the the stack in that case ?

Comment by Noel Dawe (Inactive) [ 08/Jul/13 ]

Right, the pink filled histogram is not part of the stack. These figures all contain one lone histogram drawn first, then a stack of three histograms with hatch fills drawn on top.

Comment by Noel Dawe (Inactive) [ 06/Oct/13 ]

Any progress on this?

Comment by Olivier Couet [ 03/Dec/13 ]

Now fixed in 5.34 and in the trunk thanks to the option "noclear".


Generated at Mon Feb 24 17:10:18 CET 2020 using Jira 8.3.4#803005-sha1:1f96e09b3c60279a408a2ae47be3c745f571388b.