Warm tip: This article is reproduced from serverfault.com, please click

gnuplot-解析UNIX时间戳(以毫秒为单位)作为时间

(gnuplot - Parsing UNIX timestamps in milliseconds as time)

发布于 2020-12-02 16:49:42

版本: gnuplot v5.3.0

语境

我正在尝试绘制以下CSV数据,其中第一列是以浮点数表示UNIX时间戳(以毫秒为单位)第二列是表示即时吞吐量(单位为s)的整数。

...
1.6069112402441587e+12,334
1.606911240244567e+12,335
1.6069112402475227e+12,336
1.6069112402481619e+12,337
...

为此,我编写了以下脚本文件:

set xdata time
set timefmt "%s"

set datafile separator comma

plot "results.csv" u 1:3

我从gnuplotV5文档中了解到,此版本支持毫秒级精度:

当前版本的gnuplot将时间存储为毫秒精度。

问题

执行plot命令后,gnuplot将对CSV文件中的每个数据条目引发以下警告,并且不会绘制任何值:

"throughput.plt", line 15: warning: time value out of range

我尝试了什么

我将数据文件第一列中的所有条目转换为以为单位的UNIX时间戳(更改e+12e+9)。这次plot执行时没有任何错误,但是精度的损失使图形过于近似而无法分析。

有没有办法gnuplot以毫秒为单位提取UNIX时间戳?

Questioner
Antoine Cotten
Viewed
0
binzo 2020-12-03 03:56:49

如果该列表示的时间已经在UNIX时间中表示为实数,set timefmt "%s"则没有必要。只需按原样读取数字即可。

但是,数据中的数字“ 1.6069112402441587e + 12”被解释为UNIX时间“ 52890/12/27 17:24:04 +0000”。因此,你将收到消息“警告:时间值超出范围”。当然,这不是你想要的时间。

如果按原样使用数据,脚本将类似于以下内容。

set xdata time

# set timefmt "%s"    ### This line is not needed!

set datafile separator comma

set format x "%H:%M\n%.4S"
set grid xtics

plot "results.csv" u ($1/1000):2 w linespoints

在此处输入图片说明