Search code examples
timeformatgnuplotrescale

Convert length of time to minute format


I am currently passing arguments to gnuplot via shell.

I am extracting data that has a timescale in milliseconds (just a raw length) The x axis is displayed with these raw values (ie 6000, 120000, 18456...) I would like to convert it to minutes or seconds via the arguments I am passing to gnuplot via my script (shell). I currently have the following argument:

"set title 'temperature stress test results for " + $sn + " on " + $datetime + "
                set term png size 1450, 800
                set xlabel 'Time(ms)'
                set ylabel 'Temperature (C)'
                set key right top
                set autoscale
                set yrange [20:55]
                set format x '%.0f'
                set grid
                set datafile sep ','
                set output '" + $pngfile + "'
                plot  '" + $_ + "' using 1:3 with lines title 'heater', '" + $_ + "' using 1:9 with lines title 'cam0', '" + $_ + "' using 1:10 with lines title 'cam1', '" + $_ + "' using 1:11 with lines title 'cam2', '" + $_ + "' using 1:12 with lines title 'cam3'"

is there a way to rescale the x axis ? I was expecting something like (x = x / 60000) to get it in minutes for example


Solution

  • Gnuplot's basic unit for time data is one second. You have data in milliseconds, so you will need to divide by 1000 before interpreting it as a time. Because your data is an absolute number of [milli]seconds rather than a clock time, you should use the relative time formats tH tM tS. These permit fractional values, and will not wrap at clock intervals. I.e. the minute count does not reset to 0 when it hits 60.

    To plot input data given in millisecond on an x axis labelled in Minutes and Seconds to millisecond precision:

    set xlabel 'Time (minutes:seconds)'
    set xtics time format "%tM:%.3tS"
    plot $DATA using ($1/1000.):3 title 'whatever'
    

    Example:

    plot sample [-1000:10000] '+' using ($1/1000.):1 
    

    enter image description here