gnuplot multiple lines with Time on X axis

I had a similar issue with gnuplot where I had a data file like:

05:07:00    0.0769  0.0769  0.0000  0.0000  0.0000  0.0000  0.0000
05:08:00    0.2308  0.2308  0.0000  0.0000  0.0000  0.0000  0.0000

I was trying to use, but it was just not working

set xdata time
set timefmt "HH:MM:SS";
plot "wed" using 0:2 t 'wtf" w lines

The fix was a couple of things, primarily using the %'s in the timefmt string and only using one letter. Also using the set format x for the output was key (and using the first column as 1 - though I had tried that also earlier).

This is the minimal output script that is working for me:

set xdata time
set timefmt "%H:%M:%S"
set format x "%H:%M"
plot "wed" using 1:2 t 'my title' w lines

Time data requires that you always specify all columns to be used. (Note also the corrected timefmt):

set timefmt "%H:%M:%S"
set xdata time
set datafile sep ','
set style data lines
plot '/tmp/info' using 1:2 title 'cpu', '' using 1:3 title 'memory%'

The reason for this is, that the timefmt may also contain spaces, so that the data used for the time axis may come from two columns. Consider the following modified data file:

23:00:39 06/08/13 21.9 2.1
23:00:44 06/08/13 21.8 2.1
23:00:49 06/08/13 21.8 2.1
23:00:54 06/08/13 21.8 2.1
23:00:59 06/08/13 21.7 2.1

The plotting commands for this format are:

set timefmt "%H:%M:%S %d/%m/%Y"
set xdata time 
set format x "%H:%M:%S"
set style data lines
plot 'mydata.dat' using 1:3 t 'cpu', '' using 1:4 t 'memory%'

To avoid confusion, it is always required that for time data all columns used by the plotting style (here with lines) are given explicitely with the using statement.


Your plot command look like this instead:

plot '/tmp/info' using 1:2 title 'cpu' with lines, '/tmp/info' using 1:3 title 'memory%' with lines

Tags:

Gnuplot