2
votes

I am trying to plot some data which has time (date) on the x-axis in the format 2015-12-20. I do not want to plot my data against the absolute date, but against the time difference between that date and another reference "zero" date. The reference date is in same format, eg: 2015-12-15.

Is it possible to have the data file in the format:

%Y-%m-%d Value

%Y-%m-%d Value

but have gnuplot create a plot in which the x-axis is number of days since a reference date?

1

1 Answers

2
votes

This isn't ideal, and there probably is a better way, but this works (I assume that column 1 is your date column and that column 2 is your y-axis value):

plot "data.txt" u ((strptime("%Y-%m-%d",strcol(1))-strptime("%Y-%m-%d","2015-12-10"))/86400.0):2

The strptime function turns a time string to an internal time representation (the number of seconds since some reference date) and the strcol function reads the string from column 1. We take the difference from the "zero" date (here we use December 10th). This will give the difference in seconds, so we divide by the number of seconds in a day, 86400 (we use 86400.0 so that it doesn't truncate to integers in the division). This will make the x-axis the number of days since the reference date.