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?
Newer versions of gnuplot support Unix timestamp format
%s
with fractional parts. You will need to update to 4.6 or 5.x or higher.Check src/time.c if you're not sure.
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 of1
in theusing
statement makes gnuplot treat the value as normal floating point number. Note, that I do not set anytimefmt
, 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:
You don't have to do anything at all, except stop fighting the default settings. For this input data:
The following commands
produce the following output
Timestamps in SSSSSSSSSS.mmm format are simply (decimal representation of) floating-point numbers, which is how GNUplot treats input columns by default.