Search code examples
graphgnuplotgraphing

Plotting time data with gnuplot


I have a file with several fields:

$ cat report.txt 
2014-04-18T14:21:19 41 33
2014-04-21T02:01:35 42 36
2014-05-14T16:47:58 36 57
2014-05-19T01:01:30 37 58
2014-05-23T01:25:06 41 59
2014-07-23T11:54:48 34 76

I would like to render a graph from it using gnuplot, presented like:

So basically

  • X-axis: Field 1 (before the T)
  • Y-Axis: Values from fields 2 and 3
  • Blue: Value of field 2
  • Red: Value of field 3

I miss basic understanding of gnuplot on how to do this. I've read the manpage, some online documentation and examples but still can't figure out how to do a simple graph like this.


Solution

  • This shall do it (tested with 4.6):

    set xdata time
    set yrange [0:70]
    
    # input date format
    set timefmt "%Y-%m-%dT%H:%M:%S"
    
    # output date format
    set format x "%Y\n%m-%d"
    
    plot \
        'report.txt' using 1:2 with lines ti "col 2", \
        'report.txt' using 1:3 with lines ti "col 3"