Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use GnuPlot to plot a time series chart from a CSV file date and time stored in separate columns?

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?

like image 939
Ivan Avatar asked Jun 06 '12 19:06

Ivan


2 Answers

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)

like image 129
mgilson Avatar answered Nov 15 '22 22:11

mgilson


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

like image 5
N Klosterman Avatar answered Nov 15 '22 22:11

N Klosterman