Welcome to OStack Knowledge Sharing 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 Answer

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...