Hello,
I want to change the labels of a TH2F’s y axis.
I attempt to do it this way:
c = ROOT.TCanvas()
f_in = ROOT.TFile("training.root","read")
CorrelationMatrixB = f_in.Get("Correlations/CorrelationMatrixB")
y = CorrelationMatrixB.GetYaxis()
y.ChangeLabel(14,-1,-1,-1,-1,-1,"m(h)")
y.SetLabelSize(0.03)
CorrelationMatrixB.Draw("COLZ TEXT")
c.Draw()
But the result remains unchanged. I am, however, able to perform similar operations on the x axis.
Could you please let me know why this doesnt work with the y axis and how to change the labels?
Thank you in advance,
Tanvi
couet
2
I guess your Y label are alphanumeric labels ? ChangeLabel does not work on them.
The Y and X labels are the same, and this worked on the X axis. So maybe thats not the problem?
couet
4
Ah ok. so I am wrong. Can you post the root file ? I will look at it.
CorrelationMatrixB.root (5.5 KB)
I uploaded a root file with just the TH2F. Many thanks for taking a look at it.
1 Like
couet
6
With the following example I see what you described (ok on X but not on Y). I need to debug.
{
auto f_in = new TFile("CorrelationMatrixB.root");
TH2F* CorrelationMatrixB = (TH2F*)f_in->Get("CorrelationMatrixB");
TAxis *y = CorrelationMatrixB->GetYaxis();
y->ChangeLabel(14,-1,-1,-1,-1,-1,"YYY");
TAxis *x = CorrelationMatrixB->GetXaxis();
x->ChangeLabel(14,-1,-1,-1,-1,-1,"XXX");
CorrelationMatrixB->Draw("COLZ TEXT");
}
Try with SetBinLabel(14,"m(h"))
instead of ChangeLabel.
CorrelationMatrixB.GetYaxis().SetBinLabel(14,“m(h)”)
this works!
couet
10
I made a pull request to fix the ChangeLabel issue. It should work also.
Thanks to have seen it.
system
Closed
13
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.