Moving and changing Statistics Box

Hi,

I’m trying to draw two histograms on one pad in a .C macro. When I try to access the statistics box of the second histogram to move it and change its color the macro crashes and I get a segmentation fault. I know that the histogram must be drawn first before accessing the stat box but this doesn’t seem to work.

I’m using the following code to access the stat box for histogram h:

void DrawPlots{

h->Draw(“SAMES”);
TPaveStats st = (TPaveStats)h->GetListOfFunctions()->FindObject(“stats”);
st->SetY1NDC(0.5); st->SetY2NDC(0.7);
st->SetTextColor(2);
h->Update();

}

I’ve noticed that if I run these lines at the command line level it works without a seg fault. Is there a way to get this to work inside the macro?

Thanks,

chris

1 Like

Hi Chris,
I guess you have to update canvas right after you’ve drawn your histo:

void DrawPlots{ ..... h->Draw("SAMES"); your_canvas->Update(); TPaveStats *st = (TPaveStats*)h->GetListOfFunctions()->FindObject("stats"); st->SetY1NDC(0.5); st->SetY2NDC(0.7); st->SetTextColor(2); h->Update(); .... }

1 Like