14

Lets' take this as the data file:

2012-06-01, 01:00, 1
2012-06-01, 02:00, 2
2012-06-01, 03:00, 4
2012-06-01, 04:00, 3
...
2012-06-02, 01:00, 5
2012-06-02, 02:00, 2
2012-06-02, 03:00, 1
2012-06-02, 04:00, 1
...

I know how to set timefmt and xdata to plot time series when date and time are represented with a single field, but how to plot this with GnuPlot when time and date are stored in separate columns?

Ivan
  • 63,011
  • 101
  • 250
  • 382

2 Answers2

18

Not too differently than you would if they were spaces...

set timefmt '%Y-%m-%d, %H:%M'
set xdata time
set datafile sep ','
plot 'test.dat' u 1:3 w lines

I don't know if you've used timefmt with spaces in it before either (for regular space separated datafiles) but in that case, you specify the column where the time-data starts -- gnuplot automatically looks however many columns it needs to fill out the full time format. Of course, you need a full using specification (in this case that means designating that the data is in the 3rd column -- note, not the second as you might expect).

(tested on gnuplot 4.4 -- OS X)

mgilson
  • 300,191
  • 65
  • 633
  • 696
  • Right now I use comma-separated data files, ISO-8601 date-time format (like 2012-06-06T14:54Z) and no spaces at all. But I am going to need need to support space-separated and comma-separated date-time values in comma-separated files. Thank you for the solution, I will try it. – Ivan Jun 06 '12 at 20:22
5

Running Arch Linux Gnuplot 4.6 patchlevel 3

I couldn't get mgilson's code snippet to work. I needed to set the xrange before it would stop complaining

all points y value undefined!

I had to

set xrange["2012-06-01, 01:00":"2012-06-02, 05:00"]

and finally got a pretty plot

N Klosterman
  • 1,231
  • 14
  • 23
  • 1
    Please post that as a comment to mgilson's answer, it is not an answer on its own. And for me his snippet works fine with 4.6.3 (Debian). – Christoph Oct 09 '13 at 08:06