Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Plotting multiple series from file using Gnuplot

Tags:

series

gnuplot

I've got a data file of the form:

Series_1 "12-Dec-2011 12:00" 32
Series_1 "12-Dec-2011 12:01" 29
Series_1 "12-Dec-2011 12:02" 27
Series_1 "12-Dec-2011 12:04" 23

Series_2 "12-Dec-2011 12:01" 45
Series_2 "12-Dec-2011 12:02" 43
Series_2 "12-Dec-2011 12:04" 38

Which I'd like to plot as a number of series on the same plot using gnuplot, but I'm new to gnuplot and I cannot figure out how the using clause should be structured here.

I wanted to plot column 2, date/time as the X axis with column 3 as the Y axis, with subsequent sections being overlaid. Is this possible? Surely the X axis doesn't always have to be in the first column?

I tried:

plot "datafile.dat" using 2:3 title 'Hits'

But got the error:

x range is invalid

Can anyone show me where I'm going wrong?

like image 404
Component 10 Avatar asked Dec 16 '11 12:12

Component 10


2 Answers

Expanding @Woltan's answer: if you want each section in a different colour/style, use the index (but then you have to separate sections by two emtpy lines):

plot 'i' index 0 using 2:4 with lines, '' index 1 using 2:4 with lines
like image 56
choroba Avatar answered Sep 20 '22 00:09

choroba


In order to plot date/time series on the x axis you need to set xdata time. Next you need to tell gnuplot in what format the date/time data is. In your case

set timefmt "%d-%b-%Y %H:%M"

should do the trick. Some examples, as well as the %X-synonyms are shown here.

You might want to set the format the x axis should be displayed. In your case maybe

set format x "%H:%M"

would make sense.

I was not able to plot your data with the quotation marks around the date/time. With this data file (Data.csv):

Series_1 12-Dec-2011 12:00 32
Series_1 12-Dec-2011 12:01 29
Series_1 12-Dec-2011 12:02 27
Series_1 12-Dec-2011 12:03 23

Series_2 12-Dec-2011 12:01 45
Series_2 12-Dec-2011 12:02 43
Series_2 12-Dec-2011 12:04 38

and this script:

set xdata time
set timefmt "%d-%b-%Y %H:%M"
set format x "%H:%M"

plot "Data.csv" u 2:4 w l

you should get this

enter image description here

result.

like image 40
Woltan Avatar answered Sep 22 '22 00:09

Woltan