I have some time dependant data displayed in a TGraph. I created a function which makes sure that the ticks gets on rounded seconds ( for example at 1s , 2s , … and not 1.1s, 2.2s, …)
It is mainly to avoid the ticks labels with ms (such as “10:00:00s15”) when ticks are placed at non-integer seconds.
TGraph* xaxis_time(TGraph *gr)
{
gr->GetXaxis()->SetTimeDisplay(1);
time_t xmin=floor(gr->GetXaxis()->GetXmin());
time_t xmax=ceil(gr->GetXaxis()->GetXmax());
gr->GetXaxis()->SetLimits(xmin,xmax); //set rounded limits
UInt_t xticks_interval=ceil((xmax-xmin)/10.);//interval between ticks to get ~10 ticks
UInt_t ndiv=((xmax-xmin)/xticks_interval); //number of ticks
gr->GetXaxis()->SetNdivisions(-ndiv); //set number of ticks
gr->GetXaxis()->SetLabelSize(0.03);
gr->GetXaxis()->SetTimeFormat("%H:%M:%S");
return gr;
}
However whenever the axis is zoomed, that setup is obviously lost.
Is there a way to call that function each time the axis get zoomed ?
Otherwise is there a way to insure that the ticks get automatically placed on rounded time ?
I get the error: "Error: Symbol gr_spectra is not defined in current scope ".
However from the 1st example in the link you gave me, it looked like local variables could be used within TExec.
below is the output when run with root -l test.C:
Processing plot.C…
Info in TCanvas::MakeDefCanvas: created default TCanvas with name c1
it works
Error: Symbol gr_spectra is not defined in current scope (tmpfile):1:
*** Interpreter error recovered ***