Good afternoon!
I want to do some drawing, but obtain ugly tick labels:
- the ‘-’ sign coincides with the digits for negative numbers;
- alignment;
- size.
Below there is a sample code along with the result.
#include <TAxis.h>
void uglyTLabels(){
TCanvas *c1 = new TCanvas("c1", "Canvas Title", 20, 20);
TH3F *h3box = new TH3F("h3box", "", 9, -4, 4, 9, -4, 4, 9, -4, 4);
float x, y, z;
for (int i = -1; i < 2; i++){
x = (float)i;
y = (float)(3 * i);
z = 1.5 / (float)(i + 2);
h3box->Fill(x, y, z);
}
//=====================================================
h3box->GetXaxis()->SetTitle("x");
h3box->GetYaxis()->SetTitle("y");
h3box->GetZaxis()->SetTitle("z");
//int nl = h3box->GetXaxis()->GetNlabels(); // => error: no member named 'GetNlabels' in 'TAxis'
int nDivisions = 4;
h3box->GetXaxis()->SetNdivisions(nDivisions);
for (int i = 0; i < nDivisions; i++)
h3box->GetXaxis()->ChangeLabel(i, -1, 0.095, 2, -1, -1, ""); // => Affects just first 3 labels
//h3box->GetXaxis()->ChangeLabel(i, -1, 0.05, 2, -1, -1, ""); // => Default font size
//h3box->GetXaxis()->ChangeLabel(i, -1, 0.025, 2, -1, -1, ""); // => First 3 labels disappear
h3box->Draw("BOX");
c1->SaveAs("result.pdf");
//=====================================================
delete h3box;
delete c1;
}
Result:
result-0.pdf (14.3 KB)
To tune the labels I have tried to use ChangeLabel
function, but didn’t succeed. Also a try to use GetNlabels()
leads to an error:
error: no member named 'GetNlabels' in 'TAxis'
Could anyone help me to obtain satisfactory tick labels, please? Thank you.
My system (under podman toolbox):
$ lsb_release -d && uname -r
Description: CentOS Linux release 7.9.2009 (Core)
6.3.0-2-amd64
$ g++ --version
g++ (GCC) 10.2.0
Copyright (C) 2020 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
$ root --version
ROOT Version: 6.26/10
Built for linuxx8664gcc on Dec 14 2022, 15:23:00
From v6-26-10@v6-26-10