->Draw("Sames"); is producing duplicates of the initial histogram stats box. (Ubuntu)

ROOT Version: 6.29/01
Platform: Ubuntu 11.3.0-1ubuntu1~22.04.1
Compiler: Not Provided


I am having issues drawing stat boxes for each individual histogram I draw on the same canvas using the Draw(“sames”) feature. I am using root on ubuntu. The problem is whenever I use Draw(“Sames”) it successfully draws a new statbox for each use, however, the stats box is for the first histogram (‘h1’ in the example below), essentially giving me duplicate stat boxes for the same histogram (in this case 3 total boxes).

Suffice to say that each histogram h{1-3} have been filled successfully and each draws as expected on the canvas. This is a issues with all my macros and the example is an incredibly simply case.

auto canvas = new TCanvas("can","title");

canvas->cd();

h1->Draw();
h2->Draw("Sames");
h3->Draw("Sames");

Does the stats box exists for the histograms. Well…

TPaveStats* st1 = (TPaveStats*)h1->FindObject("stats");

st1 is valid pointer (not a null pointer)
but…

TPaveStats* st2 = (TPaveStats*)h2->FindObject("stats");

st2 is a null pointer.

So I attempted to to manually give h2 (and also h3) its own stats box before drawing it using

TPaveStats *stat2 = new TPaveStats(0.5,0.6,0.8,0.9);
stat2->SetName("stats");
h2->GetListOfFunctions()->Add(stat2);

Now

TPaveStats* st2 = (TPaveStats*)h2->FindObject("stats");

Produces a valid pointer (st2), however, when I plot h2->Draw(“sames”) it still produces a stats box for h1 somehow, though it is clearly a new stats box with new graphics and in a new position replacing the original formed previously from the sames, so I still have 3 stats boxes.

Any advice how to solve this?

Just for completeness this is the ROOT startup screen for me.

Welcome to ROOT 6.29/01                    
| (c) 1995-2022, The ROOT Team; conception: R. Brun, F. Rademakers |
| Built for linuxx8664gcc on Jul 26 2023, 18:44:00                 |
| From heads/master@v6-29-01-2158-ga8333f8bb0                      |
| With c++ (Ubuntu 11.3.0-1ubuntu1~22.04.1) 11.3.0                 |

Welcome to the ROOT forum.

One of the standard examples using this option is transpad.C. If we take it as starting point, do you see the same problem ith this example?

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