gnuplot - 将 x 轴上的 unix 时间戳格式化为日期 - 时间

时间:2021-01-05 16:38:21

标签: gnuplot

我有以下格式的数据:

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:2,但同时,x tic 应该是某种预定义格式的第一列的相应时间。

1 个答案:

答案 0 :(得分:1)

检查文档 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

结果:

enter image description here