Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

gnuplot multiple lines with Time on X axis

Tags:

gnuplot

I've had a look through questions but still can't get this working.

My data set is like this:

[date] , [%cpu] , [mem]
23:00:39 , 21.9 , 2.1
23:00:44 , 21.8 , 2.1
23:00:49 , 21.8 , 2.1
23:00:54 , 21.8 , 2.1
23:00:59 , 21.7 , 2.1

My Gnuplot statements (just started using for this data) is:

set timefmt "%H:%m:%s"
set xdata time
set datafile sep ','
plot '/tmp/info' using 2 title 'cpu' with lines, '/tmp/info' using 3 title 'memory%' with lines

I get the following error:

    Need full using spec for x time data

I've tried autoscale x , but I'm a bit lost, any help would be appreciated.

like image 628
Neil R Wylie Avatar asked Aug 08 '13 04:08

Neil R Wylie


1 Answers

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.

like image 67
Christoph Avatar answered Sep 18 '22 12:09

Christoph