I couldn't get it to work with set xdata time
, because for the output only the day of the month is available, which is in the range [1:31]
, so the 0
-position would start with 1
. The same happens for total number of hours, because that value is limited to [0:23]
, so that number over 23
are wrapped back.
Here is a solution without time data. I use the strptime
function to convert the date string to a time stamp (in seconds), which is then divided by 3600 to get the hour (as float number):
The test data file is:
2013-08-25 18:45:11 100
2013-08-25 19:11:23 200
2013-08-25 20:00:32 400
2013-08-25 21:00:32 300
2013-08-26 20:11:12 500
And the example script:
reset
file='data.txt'
fmt="%Y-%m-%d %H:%M:%S"
start=system('head -1 '.file)
start_stamp = strptime(fmt, start)
plot 'data.txt' using ((strptime(fmt, stringcolumn(1).' '.stringcolumn(2))-start_stamp)/3600.0):3 with lines t ''
The first column is extracted with an external tool.
The result is:

And here is another variant, which uses a more comfortable data format, using commas as separators, and the first column is extracted with gnuplot:
The data file:
2013-08-25 18:45:11,100
2013-08-25 19:11:23,200
2013-08-25 20:00:32,400
2013-08-25 21:00:32,300
2013-08-26 20:11:12,500
The script file:
reset
file='data.txt'
fmt="%Y-%m-%d %H:%M:%S"
set datafile separator ','
plot 'data.txt' using ($0 == 0 ? start_stamp = strptime(fmt, stringcolumn(1)) : 0, \
(strptime(fmt, stringcolumn(1))-start_stamp)/3600.0):2 with lines t ''
The results are equivalent.
EDIT: One last variant, which is a mixture @andyras's and my answer. You can use set timefmt
with an explicit call to timecolumn
to parse the input as time. The output is then handled like a conventional double number. I use $0
, i.e. the number of the current sample, to set the offset value:
reset
set timefmt "%Y-%m-%d %H:%M:%S"
offset = 0
t0(x)=(offset=($0==0) ? x : offset, x - offset)
plot 'data.txt' u (t0(timecolumn(1))/3600.0):3 notitle w l