首页 > 解决方案 > gnuplot - 将 x 轴上的 unix 时间戳格式化为日期 - 时间

问题描述

我有以下格式的数据:

1609257628 2
1609256682 4
1609255914 1

其中第一列应该在 x 轴上并且是 unix 时间戳。有没有办法生成可读的日期,例如格式为“%d.%m.%Y %H:%M”,同时保持数据点在 x 轴上的空间相等?

我试过:

set format x "%d.%m.%Y %H:%M"
plot data  u 0:2:xticlabels(1) w l t 

但它什么也不做,绘制时间戳。所以我更简单地尝试了:

set format x "%d.%m.%Y %H:%M"
plot data u 1:2 w l

但我明白了

Bad format character

无论如何,目标是同时拥有plot using 0:2x tic 应该是从第一列以某种预定义格式的相应时间。

标签: gnuplot

解决方案


检查文档help strftime并尝试以下操作:

代码:

### plot timedata equidistant as xtic label
reset session

$Data <<EOD
1609257628 2
1609256682 4
1609255914 1
EOD

myTimeFmt = "%d.%m.%Y %H:%M"

plot $Data u 0:2:xtic(strftime(myTimeFmt,column(1))) w lp pt 7
### end of code

结果:

在此处输入图像描述


推荐阅读