Hello,
I illustrate the problem modifying the example that you provide at root.cern.ch/root/html532/THStack.html:
{
THStack hs(“hs”,“test stacked histograms”);
TH1F h1 = new TH1F(“h1”,“test hstack; Xaxis_title; Yaxis_title”,100,-4,4);
h1->FillRandom(“gaus”,20000);
h1->SetFillColor(kRed);
hs.Add(h1);
TH1F h2 = new TH1F(“h2”,“test hstack; Xaxis_title; Yaxis_title”,100,-4,4);
h2->FillRandom(“gaus”,15000);
h2->SetFillColor(kBlue);
hs.Add(h2);
TH1F h3 = new TH1F(“h3”,“test hstack; Xaxis_title; Yaxis_title”,100,-4,4);
h3->FillRandom(“gaus”,10000);
h3->SetFillColor(kGreen);
hs.Add(h3);
TCanvas c1(“c1”,“stacked hists”);
printf("%p %p\n", (void)hs.GetXaxis(), (void)hs.GetYaxis());
hs.Draw();
}
The THStack is drawn without axes titles although all of the histograms have them. This is a completely undesired result.
Furthermore, it is not possible to add axes titles to the THStack because the line
printf("%p %p\n", (void)hs.GetXaxis(), (void*)hs.GetYaxis());
prints
(nil) (nil)
A THStack without axes titles is not what we desire.
Regards,
Viesturs
Try: // ...
THStack hs("hs", "My Global Title;My X Axis Title;My Y Axis Title");
// ...
hs.Draw();
gPad->Modified(); gPad->Update(); // make sure it's really (re)drawn
printf("%p %p\n", hs.GetXaxis(), hs.GetYaxis());
// ...
and/or: // ...
THStack hs("hs", "My Global Title");
// ...
hs.Draw();
gPad->Modified(); gPad->Update(); // make sure it's really (re)drawn
printf("%p %p\n", hs.GetXaxis(), hs.GetYaxis());
hs.GetXaxis()->SetTitle("My X Axis Title");
hs.GetYaxis()->SetTitle("My Y Axis Title");
gPad->Modified(); gPad->Update(); // make sure it's really (re)drawn
// ...
2 Likes
Thank you, it worked.