Search code examples
gnuplot

Gnuplot misreads time data


I can't seem to get gnuplot to properly plot my time data. (I'm using version 4.6, patchlevel 3.)

For an MWE (well, non-working...), the input file

reset

set xdata time
set timefmt "%H:%M:%S"
set format x "%H:%M:%S"

plot '-' using ($1):($2) with lines lw 3
15:36:12  1.0
15:43:17  3.0
16:12:02  2.0
e

produces the following output: enter image description here

Apparently, gnuplot interprets the hours as seconds and ignores the rest. I have tried a bunch of other format strings (also single/double quotes), but gnuplot seems to ignore everything except the first number.

Is something wrong with my format, or is this a bug, or something else?


Solution

  • With $1 you explicitely select the numerical value of the first column, which bypasses any gnuplot automatism to interpret the column values as appropriate (as time value in your case). Simply use using 1:2:

    reset
    set xdata time
    set timefmt "%H:%M:%S"
    set format x "%H:%M:%S"
    
    plot '-' using 1:2 with lines lw 3
    15:36:12  1.0
    15:43:17  3.0
    16:12:02  2.0
    e
    

    Use the syntax $1 only when doing calculations with the actual numerical value in the respective column. $1 is a shortcut for column(1), gnuplot also knows stringcolumn(1) and timecolumn(1) for other purposes.