- not so Frequently Asked Questions -
not so FAQ
To plot a data file which contains date or time, you need to tell gnuplot that the data are date/time type by the command set xdata time or set ydata time , then specify the data file format by set timefmt . Let's begin with the following example:
2004-02-09 310 2004-02-10 185 2004-02-11 239 2004-02-12 132 2004-02-13 85 2004-02-14 57 2004-02-15 8
A corresponding timefmt to read this data is "%Y-%m-%d". In this case zero's are padded when month and/or date are less than 10, but gnuplot can read data without this padding (2004-2-9, for example).
gnuplot> set xdata time gnuplot> set timefmt "%Y-%m-%d" gnuplot> plot "sample.dat" using 1:2 with boxes
Reading date/time data with gnuplot is rather flexible. Here are some examples of the format given for timefmt.
When gnuplot reads in date/time type data as X-axis data, it generates appropriate X-tics automatically. In the example above, which are time sequence data for one week, gnuplot writes "month/day" on the X-axis, plus time of "00:00" which we may not need. To control the output format, use set format . This format specification not the same as usual numerical output, but it is a format for the strftime function of UNIX library.
gnuplot> set xdata time gnuplot> set timefmt "%Y-%m-%d" gnuplot> set format x "%b/%a" gnuplot> plot "sample.dat" using 1:2 with boxes
In addition to the format-characters shown above, you can use "%a" which does not exist in timefmt . With the "%a" format gnuplot gives you a weekday name. See manual of strftime function in detail. Anyway, formats such as "Y, y, m, d, H, M, S" are probably enough for almost all cases.