Plotting with dates and times
gnuplot is capable of handling data plotted along a date/time axis and can understand and display dates and times in a variety of formats.
Getting ready
If you are plotting data versus time, you are almost certainly dealing with data tabulated in a file. We have supplied a small file for this recipe called timedat.dat
; it consists of a few lines of data, each line containing a date, time, and a number to be plotted. The dates are in the form day/month/2-digit-year, and the times are in the form hour:minute. Following is the first line:
1/1/11 19:00 72.01
The following figure shows plotting with dates using gnuplot:
Note that the tics along the bottom axis are labeled as dates.
How to do it…
Following is the script that we used to get the previous figure:
set xdata time set timefmt "%d/%m/%y %H:%M" set format x "%d/%m/%y" plot 'timedat.dat' using 1:3 with linespoints
How it works…
When dealing with date/time data, you must always alert gnuplot to this with set xdata time...