I am a newbie and using pyROOT as I am more comfortable with Python. I have a TGraph object with a TF1 fit (linear). My x-axis ticks should be linear, and in multiples of 512 (digital-to-analog converter counts, 0 to 4095.). It should look like 0, 512, 1024, 1536, … 4096. But by default, it is in multiples of 500. Is there any way to change the default ticks? ChatGPT isn’t very helpful.
ROOT Version: 6.28
Platform: Ubuntu 23.04
Compiler: python3 + pyROOT
Welcome to the ROOT Forum!
Maybe @couet can help
couet
August 15, 2023, 9:08am
3
Such axis labeling will not be easy to obtain automatically. Maybe you can get some inspiration from the following example:
void graphtext3() {
TCanvas *c = new TCanvas("c","A Simple Graph with labels on points",700,500);
const Int_t n = 10;
TGraph *gr = new TGraph(n);
gr->SetTitle("A Simple Graph Example with Text");
gr->SetMarkerStyle(20);
TExec *ex = new TExec("ex","DrawText();");
gr->GetListOfFunctions()->Add(ex);
Double_t x, y;
for (Int_t i=0;i<n;i++) {
x = i*0.1;
y = 10*sin(x+0.2);
gr->SetPoint(i,x,y);
}
gr->Draw("ALP");
gr->GetXaxis()->SetLabelSize(0);
gr->GetXaxis()->SetTickLength(0);
}
void DrawText()
{
Int_t i,n;
Double_t x,y;
TLatex *t;
TLine *l;
TGraph *g = (TGraph*)gPad->GetListOfPrimitives()->FindObject("Graph");
double ymin = g->GetHistogram()->GetMinimum();
double ymax= g->GetHistogram()->GetMaximum();
double dy = (ymax-ymin);
n = g->GetN();
for (i=0; i<n; i++) {
g->GetPoint(i,x,y);
t = new TLatex(x, ymin-0.03*dy, Form("%4.2f",x));
t->SetTextSize(0.025);
t->SetTextFont(42);
t->SetTextAlign(21);
t->Paint();
l = new TLine(x,ymin,x,ymin+0.03*dy);
l->Paint();
}
}