Problem with Time Display

Please read tips for efficient and successful posting and posting code

ROOT Version: 6.20/02
Platform: MacBookAir macOS Catalina v 10.15.5
Compiler: Not Provided

I have generated temperature values as a function of date and time, see my code TimePlot.C.
I include the resulting plot (TemperatureVsDate.pdf) and text output (TemperatureVsDate.txt). As you can see, although the points seem to be correctly plotted, the labels on the time axis are wrong: equal distance correspond to non-equal time differences (22/07 and 26/07 are separated with the same distance as 26/07 and 29/07). In a more general term: how can one enforce the ticks on a time display? In my case, I’d like to see ticks corresponding to days and hours, but don’t know how to modify my code to achieve this. Thanks for your help.

TemperatureVsDate.pdf (15.4 KB)

TemperatureVsDate.txt (5.4 KB)

TimePlot.C (1.8 KB)

You can increase the number of divisions on the X axis:


Thanks, it works also in my macro I have sent yesterday. Could you please tell me how can one get the magic number 513 in the argument? I’m asking this because in another of my macros, where I have less numbers to plot, this update doesn’t work. It seems to me that the code selects the time axis according to the number of points to be plotted and graph->GetXaxis()->SetNdivisions(513);
works in some case and doesn’t work in another one. Elemer

Nothing magic with 513. It is just a larger number of divisions. See here

It seems that the second argument has to be set to 0 otherwise it starts “optimize”.
Even with that, i.e. with gt->GetXaxis()->SetNdivisions(215,0); in my other macro, I see that the labels are sometimes repeated, like 21/07 and 29/07 in the plot I upload now, which is clearly wrong and points to some problem. Elemer
TemperatureLast.pdf (15.3 KB)

It is better to let optimise on and increase the number of primary divisions.

Excellent suggestion, gt->GetXaxis()->SetNdivisions(515); is working for my other macro as well. Many thanks for your help, Elemer

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.