Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.2k views
in Technique[技术] by (71.8m points)

gnuplot -formating unix timestamp on x axis as date - time

I have the following format of data:

1609257628 2
1609256682 4
1609255914 1

where the first column should be on x axis and is the unix timestamp. Is there any way to generate a readable date such as in format "%d.%m.%Y %H:%M" and at the same time keeping the data points equally space on x axis?

I tried:

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

But it does nothing, plots the timestamp. So I tried more simply:

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

But i get

Bad format character

Anyway, the goal is to have the plot using 0:2 but at the same time, x tics should be the corresponding time from the first column in some predefined format.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Check the documentation help strftime and try the following:

Code:

### 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

Result:

enter image description here


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...