我们可以绘制时间,作为UNIX时间戳,并添加毫秒吗? [英] Can I plot times when they're given as UNIX timestamps with added milliseconds?

查看:201
本文介绍了我们可以绘制时间,作为UNIX时间戳,并添加毫秒吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在CentOS 6.6上使用gnuplot 4.4。



我发现很多%。3S )将启用 12:42:51.047 等时间戳,并将其用作X轴值: / p>

  set xdata time 
set format x%H:%M:%。3S
set timefmt %H:%M:%S

但是,我的输入不像 HH:MM:SS.mmm 但像 SSSSSSSSSS.mmm ,其中整体部分是UNIX时间戳。



我尝试了以下内容,但解析似乎已经失败,因为所有数据点在00:00:00呈现:

  set xdata time 
set format x%.3s
set timefmt%H:%M:%S

manu al 没有表明这是可能的,但是再一次,它并不表示%H:M:%。3S 正在进行也可以工作。
有可能做我想做的事吗?如果是,那么怎么样?

解决方案

精度必须仅用于输出。对于解析,秒(或时间戳)被视为浮点数。但是,自从版本4.6.4(在这里进行测试)以来,以毫秒为单位读取时间戳似乎是受支持的。



但是,有一个解决方法:指定而不是使用语句的中的 1 使得gnuplot处理该值作为正常浮点数。请注意,我没有设置任何 timefmt ,因为它将被这种解决方法所规避。



然后你还必须知道,在版本5之前,gnuplot的时间参考是2000年1月1日,所以你必须通过相应的偏移量(Unix时间戳,2000年1月是946684800)进行纠正。所以,以下工作与gnuplot 4.4:

 设置xdata时间
设置格式x'%d。%m。 %Y%H:%M:%S'
plot'file.dat'using($ 1 - 946684800):2


I'm using gnuplot 4.4 on CentOS 6.6.

I've found many examples online showing that the following (note the use of %.3S) will enable timestamps like "12:42:51.047" to be parsed and used as X axis values:

set xdata time
set format x "%H:%M:%.3S"
set timefmt "%H:%M:%S"

However, my input is not like HH:MM:SS.mmm but like SSSSSSSSSS.mmm, where the integral part is a UNIX timestamp.

I tried the following, but the parsing appeared to have failed since all datapoints rendered at "00:00:00":

set xdata time
set format x "%.3s"
set timefmt "%H:%M:%S"

The manual doesn't give any indication that this is possible but, then again, it doesn't say that the %H:M:%.3S was going to work, either. Is it possible to do what I want to do? If so, how?

解决方案

The precision must be given only for the output. For parsing, the seconds (or the timestamp) are treated as floating numbers. But reading in a time stamp with milliseconds seems to be supported only since version 4.6.4 (tested here).

But, there is a workaround: specifying ($1) instead of 1 in the using statement makes gnuplot treat the value as normal floating point number. Note, that I do not set any timefmt, since it would be circumvented by this workaround anyway.

Then you must also know, that before version 5, gnuplot's time reference is the 1. Jan. 2000, so you must correct by the respective offset (Unix time stamp of the 1. Jan 2000 is 946684800). So, the following works with gnuplot 4.4:

set xdata time
set format x '%d.%m.%Y %H:%M:%S'
plot 'file.dat' using ($1 - 946684800):2

这篇关于我们可以绘制时间,作为UNIX时间戳,并添加毫秒吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆