Search code examples
gnuplot

Unexpected behaviour with negative fraction of seconds in xdata time


Can anybody explain the strange behaviour of gnuplot with negative fractions of seconds when plotting with xdata time? I mean the zig-zag in the middle plot. Is this a bug or am I missing anything? (gnuplot 5.2.6)

Code:

### strange behaviour with negative fractions of seconds in xdata time
reset session

set table $Data
    plot '+' u 1:($1**2) w table
unset table

set multiplot layout 3,1
    plot $Data u 1:2 w lp pt 7 lc rgb "web-green"

    set xdata time
    set timefmt "%s"
    set format x "%H:%M:%S"
    plot $Data u 1:2 w lp pt 7 lc rgb "red"

    set format x "%H:%M"
    plot $Data u ($1*60):2 w lp pt 7 lc rgb "web-blue"

unset multiplot
### end of code

Result:

enter image description here


Solution

  • You are over-complicating this. Your data is purely in seconds. No need to invoke "set xdata time" or "set timefmt" variants because the input is just a floating point number. On output, set the xtic format depending on whether you want the x axis labeled in absolute time (wraps at midnight) or relative time (+/- interval).

    ### absolute vs relative time formats
    set table $Data
        plot '+' u 1:($1**2) w table
    unset table
    
    set multiplot layout 3,1
        plot $Data u 1:2 w lp pt 7 lc rgb "web-green"
    
        set xtics time format "%tH:%tM:%tS" # relative time
        plot $Data u 1:2 w lp pt 7 lc rgb "red"
    
        set xtics time format "%H:%M:%S"    # absolute time
        plot $Data u 1:2 w lp pt 7 lc rgb "blue"
    unset multiplot
    ### end of code
    

    enter image description here

    But no, sorry, I cannot explain why your original plot came out with a zigzag.