使 gnuplot 解析日期和时间如“2022-01-24 05:36:22”时出现问题

Problem making gnuplot parse date and time like "2022-01-24 05:36:22"

看来我的gnuplot知识越来越生疏了;至少我看不出有什么问题:

我有一个这样的数据文件(实际文件有 50000 多行,字段由 TAB 分隔):

#date-and-time(0)   1(1)    5(2)    9(3)    12(4)   13(5)   170(6)  174(7)  179(8)  180(9)  181(10) 182(11) 184(12) 194(13) 195(14) 197(15) 198(16) 199(17) 201(18) 202(19) 225(20) 226(21) 227(22) 228(23) 232(24) 233(25) 234(26) 241(27) 242(28) 245(29)
2022-01-24 05:36:22 130 100 100 100 95  100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100
2022-01-24 06:06:22 130 100 100 100 95  100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100
2022-01-24 06:36:22 130 100 100 100 95  100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100
2022-01-24 07:06:22 130 100 100 100 95  100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100

gnuplot 会话如下所示:

Terminal type is now 'qt'
gnuplot> plot "attrlog.short" using 1:6 with linesp
Warning: empty x range [2022:2022], adjusting to [2001.78:2042.22]
Warning: empty y range [100:100], adjusting to [99:101]
gnuplot> set dataf sep tab
gnuplot> set form x "%F %T"
gnuplot> set timefmt "%F %T"
gnuplot> set xdata time
gnuplot> repl
2022-01-24 05:36:22 130 100 100 100 95  100 100 100 100 100 100 100 100 100 10...
attrlog.short:2:         warning: Bad time format in string
2022-01-24 05:36:22 130 100 100 100 95  100 100 100 100 100 100 100 100 100 10...
attrlog.short:2:         warning: Bad time format in string
2022-01-24 06:06:22 130 100 100 100 95  100 100 100 100 100 100 100 100 100 10...
attrlog.short:3:         warning: Bad time format in string
2022-01-24 06:06:22 130 100 100 100 95  100 100 100 100 100 100 100 100 100 10...
attrlog.short:3:         warning: Bad time format in string
2022-01-24 06:36:22 130 100 100 100 95  100 100 100 100 100 100 100 100 100 10...
attrlog.short:4:         warning: Bad time format in string
2022-01-24 06:36:22 130 100 100 100 95  100 100 100 100 100 100 100 100 100 10...
attrlog.short:4:         warning: Bad time format in string
2022-01-24 07:06:22 130 100 100 100 95  100 100 100 100 100 100 100 100 100 10...
attrlog.short:5:         warning: Bad time format in string
2022-01-24 07:06:22 130 100 100 100 95  100 100 100 100 100 100 100 100 100 10...
attrlog.short:5:         warning: Bad time format in string
Warning: empty x range [0:0], adjusting to [-1:1]
Warning: empty y range [95:95], adjusting to [94.05:95.95]
gnuplot> set form x "%Y-%m-%d %T"
gnuplot> set timefmt "%Y-%m-%d %T"
gnuplot> repl
2022-01-24 05:36:22 130 100 100 100 95  100 100 100 100 100 100 100 100 100 10...
attrlog.short:2:         warning: Bad time format in string
2022-01-24 06:06:22 130 100 100 100 95  100 100 100 100 100 100 100 100 100 10...
attrlog.short:3:         warning: Bad time format in string
2022-01-24 06:36:22 130 100 100 100 95  100 100 100 100 100 100 100 100 100 10...
attrlog.short:4:         warning: Bad time format in string
2022-01-24 07:06:22 130 100 100 100 95  100 100 100 100 100 100 100 100 100 10...
attrlog.short:5:         warning: Bad time format in string
Warning: empty x range [1.64298e+09:1.64298e+09], adjusting to [1.62655e+09:1.65941e+09]
Warning: empty y range [95:95], adjusting to [94.05:95.95]
gnuplot> 

最初我使用“%F”而不是“%Y-%m-%d”,但即使现在它也不起作用,我不明白为什么。 示例会话是使用 gnuplut 5.2 patchlevel 2 创建的,而最初问题是在 5.2 patchlevel 8 中发现的。

数据格式应该很明显:YYYY-MM-DD HH:MM:SS

占位符 %F(日期)和 %T(时间)对于 set timefmt 无效。 因此,当改用这些命令时,事情应该会顺利进行:

set xdata time
set timefmt "%Y-%m-%d %H:%M:%S"

plot "attrlog.short" u 1:6 w lp

详情见help time_specifiers:

%F and %T are only for output, not for input as you are trying.

  • 输出:set format x '%F %T' 可以,但是

  • 输入:set timefmt '%F %T' 不会 根据文档工作。 将其更改为 set timefmt '%Y-%m-%d %H:%M:%S'.

注意: 如果您想在数据示例中绘制带有 95 的列

  • 如果您的分隔符是白色space(默认),您必须指定第 7 列。

  • 并且如果您明确将 TAB 作为分隔符(这是您稍后指定的内容)并且 date/time 中的 space 是“正常” space 那么列6 就可以了。