6

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?

Component 10
  • 10,247
  • 7
  • 47
  • 64
  • also see: http://stackoverflow.com/questions/12818797/gnuplot-plotting-several-datasets-with-titles-from-one-file – kolypto Aug 29 '14 at 00:00

2 Answers2

12

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
choroba
  • 231,213
  • 25
  • 204
  • 289
8

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.

Community
  • 1
  • 1
Woltan
  • 13,723
  • 15
  • 78
  • 104
  • Thanks. I included the quotes as, in the help section it states: ...white space divides each record into columns. However, whitespace inside a pair of double quotes is ignored when counting columns, so the following datafile line has three columns: 1.0 "second column" 3.0 – Component 10 Dec 16 '11 at 14:26