Hi Folks,
I’m trying to draw a THStack with one set of axis titles, then modify the content histograms and draw the stack again with different axis titles.
However whilst preparing code for this I ran into the following problem: Having set the axis titles of the THStack when constructing it, I’m then unable to edit the titles. Here’s a little test macro to demonstrate the problem:
#include "TCanvas.h"
#include "THStack.h"
#include "TH1D.h"
#include "TRandom.h"
void testplot(){
TH1D * h = new TH1D("h","",10,-2,2);
TRandom *r = new TRandom();
double x;
for(int i=0;i<10000;i++){
x = r->Gaus(0,1);
h->Fill(x);
}
TCanvas *c = new TCanvas("c","c");
THStack *hs = new THStack("hs","Title ;X axis; Y axis");
hs->Add(h);
hs->Draw("HIST");
//no combination of these will change the Y axis title
hs->GetHistogram()->GetYaxis()->SetTitle("New Title");
//hs->GetYaxis()->SetTitle("New Title");
//gPad->Update();
//gPad->Modified();
c->Update();
c->Modified();
}
No combination of the lines trying to update the canvas or using hs->GetHistogram()->GetYaxis() instead of hs->GetYaxis() results in the new y axis title being used.
Please read tips for efficient and successful posting and posting code
_ROOT Version:_6.18/04
Platform: Not Provided
Compiler: