Search code examples
gnuplot

gnuplot: histogram of events: issue with timecolumn()


I would like to see the number of events per timeperiod.

My rows look like this

"2020-11-11 09:15:50",field2,field3

This is what I have tried

binwidth = 3600 # 1h in seconds
bin(t) = (t - (int(t) % binwidth) + binwidth/2)
set datafile separator ","
#set xdata time
set timefmt '"%Y-%m-%d %H:%M:%S"'
set boxwidth binwidth
plot 'Statistics.log' using (bin(timecolumn(1, '"%Y-%m-%d %H:%M:%S"'))):(1) smooth freq with boxes

I'm getting

unknown type in magnitude()

How would I debug errors like these? (How do I dump what gnuplot "sees" for timecolumn() etc.?)

(gnuplot 4.6)


Solution

  • At first, The timecolumn() in gnuplot 4.6 is a single-argument function, and only the argument for the column number is allowed. Therefore, the plot command can be rewritten as,

    plot "test.dat" using (bin(timecolumn(1))):(1) smooth freq with boxes
    

    Secondly, do not include leading and trailing double quotes in your timefmt formatting.

    set timefmt '%Y-%m-%d %H:%M:%S'
    
    

    For more information about this, please refer to the "help data" section.

    ...

    However, whitespace inside a pair of double quotes is ignored when counting columns, so the following datafile line has three columns:

    1.0 "second column" 3.0

    Finally, your code can be modified as follows (for gnuplot 4.6)

    binwidth = 3600 # 1h in seconds
    bin(t) = (t - (int(t) % binwidth) + binwidth/2)
    set datafile separator ","
    set xdata time
    set timefmt '%Y-%m-%d %H:%M:%S'
    set boxwidth binwidth
    plot 'Statistics.log' using (bin(timecolumn(1))):(1) smooth freq with boxes