Search code examples
gnuplot

Set xrange for time correctly


I try to plot a file containing timestamps of the format YEAR-MONTH-DAY HOUR and an positive integer separated by a tabulator. GNUPlot seems unable to extract the start end endtime of the given file telling me

Warning: empty x range [6.31152e+08:6.31152e+08], adjusting to [6.2484e+08:6.37464e+08]

But even telling the xrange explicitly does not improve the result

"sumChangePlot.p", line 12: Can't plot with an empty x range!

This is the related code of my plot file

set datafile separator "\t"
set xdata time
set timefmt '%y-%m-%d %H'
set xrange ['2014-11-06 00':'2014-11-12 24']

and this is an excerpt of my data file (containing data of this type until the 12th)

2014-11-6 19    1
2014-11-6 20    1
2014-11-6 21    2
2014-11-6 22    2
2014-11-6 23    2

How can I make GNUPlot understand the xrange given in the file? (prefered automatically but if manually is the only choice so be it)


Solution

  • In order to use a four-digit year you must use %Y (capital letter) in the format string:

    set datafile separator "\t"
    set xdata time
    set timefmt '%Y-%m-%d %H'
    set xrange ['2014-11-06 00':'2014-11-12 24']
    plot 'file.txt' using 1:2