Changing labels in TTree::Draw()

Hello,

Running into the same issue for quite some time, I finally decided to post a thread here. My question is the following: is there a way to change the automatic labels of title, X and Y axis when plotting from a TTree?

To be more specific: when plotting one quantity versus another using TTree::Draw(“y : x”), the title and axis names are automatically set to the name of the quantities (here, y and x). But I don’t see any way of changing these names afterwards. I know how to change them in a TH1F or in a TGraph. But I don’t see how to do that directly from a TTree. I know that the TTree::Draw() command automatically produces a histogram called “htemp”, but I didn’t succeed to change it.

On the other hand, I succeeded to change the axis name by sending the output of the command to a histogram (TTree::Draw(“y : x>>hh”)), but this results in a histogram which has a “step-like” structure, i.e. does not look like the original TTree::Draw(“y : x”). So I am not satisfied with this solution.

Could someone help me with this?

Thank you in advance

After your TTree::draw command, do

TH2F *htemp = (TH2F*)gPad->GetPrimitive("htemp"); htemp->GetXaxis()->SetTitle("my new X title"); htemp->GetYaxis()->SetTitle("my new Y title");
Rene

Hello Rene,

Thank you for the answer. However this doesn’t solve the problem. Using these commands, I can change the labels, but all the points in the plot are gone…

Cheers
Dominique

Could you post teh shortest possible running script reproducing the problem?

Rene

void problem(){ int npoint=100; double x,y; TTree *t=new TTree("t","t"); t->Branch("x",&x,"x/D"); t->Branch("y",&y,"y/D"); for (int i=0;i<npoint;i++){ x=(double)i/(npoint/2); y=x*x; t->Fill(); } t->SetMarkerStyle(3); t->Draw("y:x"); TH2F *htemp = (TH2F*)gPad->GetPrimitive("htemp"); htemp->GetXaxis()->SetTitle("my new X title"); htemp->GetYaxis()->SetTitle("my new Y title"); htemp->Draw(); }

Tested with ROOT 5.18 and 5.25

Remove the last line “htemp->Draw()”, simply update your canvas.
The htemp histogram is only used to set the range, the real data being in a TGraph.
To see what you have in the pad, do
gPad->ls();

Rene

OK thanks, this works, but only when I click on Options->Refresh in the canvas. Writing c1->Update() does not change anything…

Hi Dominique,

Try gPad->Update() instead of c1->Update() (c1 is not known - at least in your macro)

Cheers, Bertrand.