【问题标题】:Gnuplot plots incorrect time for time series plotGnuplot 为时间序列图绘制不正确的时间
【发布时间】:2014-07-11 07:15:21
【问题描述】:

我正在打印具有以下格式的时间序列

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

第一列是 unix 纪元格式的时间戳,第二列是要绘制的变量。 请注意,第一行的时间戳对应于“Tue May 20 00:00:53 CEST 2014”,最后一行对应于“Tue May 20 23:50:53 CEST 2014”。我使用以下命令验证了这一点:

date -d @<timestamp>

我正在使用以下脚本来绘制时间序列

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

但我得到了一个小时数在 22、00、02....22 范围内的图,如下图所示:

我将不胜感激有关如何解决此问题的任何建议。这可能与未正确设置时区有关吗?非常感谢提前

【问题讨论】:

  • 我刚刚在另一个 stackoverflow 的问题中遇到了this comment。显然,这是 gnuplot 的一个限制,当从纪元开始以秒为单位转换时间戳时,它总是假定世界时。

标签: plot gnuplot time-series


【解决方案1】:

Gnuplot 无法更改时区,所有时间数据都使用 UTC。这就是您的 2 小时班次的来源:

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

在您的具体情况下,您只需在 using 语句中添加两个小时:

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

请注意,这明确假设您仅在同一时区的计算机上运行脚本。我认为在 gnuplot 中没有通用的时区转换方法,因为它不支持它们。

【讨论】:

    【解决方案2】:

    在Christoph's answer 之后,我弄清楚了如何在调用 gnuplot 的脚本中以通用方式计算偏移量:

       LOCAL=$(date)
       UTC=$(date -u -d "$LOCAL" +"%Y-%m-%d %H:%M:%S")  #remove timezone reference
       UTCSECONDS=$(date -d "$UTC" +%s)
       LOCALSECONDS=(date -d "$LOCAL" +%s)        
       TIMEZONEGAP=$(($LOCALSECONDS-$UTCSECONDS))
    

    然后在 gnuplot 中我可以按照建议使用这个间隙

    【讨论】:

    • 有一个错字:LOCALSECONDS=$(date -d "$LOCAL" +%s) 我被拒绝更正,因为编辑太短了!
    猜你喜欢
    • 2016-01-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-10
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多