plotgnuplottime-series

Gnuplot plots incorrect time for time series plot


I'm printing a time series that has the following format

> 1400536853 0.011955 
> 1400537188 0.013695 
> 1400537530 0.010797  
> ....
> 1400621709 0.010688 
> 1400622023 0.007209 
> 1400622338 0.006685 
> 1400622653 0.005539

The first column is a timestamp in unix epoch format and the second is a variable to plot. Notice that the timestamp pf the first line corresponds to "Tue May 20 00:00:53 CEST 2014" and the last line to "Tue May 20 23:50:53 CEST 2014". I veridied this with the following command:

date -d @<timestamp>

I'm using the following script to plot the time series

set xdata time
set timefmt '%s'
set format x '%H'
plot 'series.txt' using 1:2 with lines notitle

But I'm getting a plot with hours in the range 22, 00, 02. ...22 as shown in the next figure:

time series plot

I will appreciate any suggestion on how to fix this. May this has to do with not setting properly the timezone? Many thanks in advance


Solution

  • Gnuplot cannot change the time zone and uses UTC for all time data. This is where your 2h shift comes from:

    $ date -u -d @1400536853
    Mo 19. Mai 22:00:53 UTC 2014
    

    In your specific case, you can just add the two hours in the using statement:

    set xdata time
    set timefmt '%s'
    set format x '%H'
    plot 'series.txt' using ($1 + 2*60*60):2 with lines notitle
    

    Beware, that this explicitely assumes, that you run the script only on computers in the same time zone. I think there is no generic way to convert between time zones within gnuplot, since it doesn't support them.