Credits Overview Plotting Styles Commands Terminals

time data

In fitting time data it is important to remember that gnuplot represents time as seconds since 1 January 1970. For example if you wanted to fit a quadratic model for the time dependence of something measured over the course of one day in 2023, you might expect that it could be done using

     T(x) = a + b*x + c*x*x
     set xdata time
     fit T(x) 'hits.dat' using 1:3 via a,b,c

This will probably fail, because internally the x values corresponding to that one day will have a range something like [1.67746e+09 : 1.67754e+09]. The fractional change in x across the measured data will be only about 1.e-05 and to guarantee convergence you would probably need many decimal places of accuracy in the initial parameter estimates.

One solution is to recast the problem as change in time since the start of measurement.

     set xdata time       # data format "27-02-2023 12:00:00 measurement"
     timefmt  = "%d-%m-%Y %H:%M:%S"
     set timefmt timefmt
     t0 = strptime( timefmt, "27-02-2023 00:00:00" )
     fit T(x) 'temperature.dat' using ($1-t0):3 via a,b,c

This shifts the range of the data to [0 : 86400], which is more tractable. Another possibility in this case is to ignore the date in column 1 and use relative time formats (tH/tM/tS) applied to column 2.

     set timefmt "%tH:%tM:%tS"
     fit T(x) 'temperature.dat' using 2:3 via a,b,c