Search code examples
gnuplot

x range is invalid. Maybe timefmt wrong


I have the following script

set datafile separator ","
set grid

set autoscale

set timefmt "%y-%m-%d %H:%M:%S"
set xdata time

plot 'test.txt' using 1:2 with lines

Data

2017-09-01 13:15:29,615,668
2017-09-01 13:15:29,615,666 
2017-09-01 13:15:29,614,666
2017-09-01 13:15:29,615,666
2017-09-01 13:15:29,615,665
2017-09-01 13:19:52,614,660
2017-09-01 13:19:52,615,661

I want to plot this data which was generated by postgresql. Since hours i cant figure out why i get

gnuplot> plot 'test.txt' using 1:2 with lines
                                             ^
         "strom-plot.txt", line 9: x range is invalid

Any hint would be appreciated.

EDIT: I am on gnuplot 5.0 patchlevel 5 debian stretch


Solution

  • The issue is an error in your timefmt argument. You should be using %Y instead of %y. From help timefmt:

    Format       Explanation
    %y           year, 0--99
    %Y           year, 4-digit
    

    This works here:

    set datafile separator ","
    set grid
    
    set autoscale
    
    set timefmt "%Y-%m-%d %H:%M:%S"
    set xdata time
    
    plot 'test.txt' using 1:2 with lines
    

    Result:

    Plot of first and second columns