Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I plot times when they're given as UNIX timestamps with added milliseconds?

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?

like image 504
Lightness Races in Orbit Avatar asked Jan 24 '26 22:01

Lightness Races in Orbit


1 Answers

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
like image 195
Christoph Avatar answered Jan 26 '26 13:01

Christoph