7

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?

1

2 Answers 2

11

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 'datafile.dat' index 0 using 2:4 with lines, '' index 1 using 2:4 with lines
Sign up to request clarification or add additional context in comments.

4 Comments

+1 choroba your answer was the resolution of a 4 hour research how to separate the sections. I haven't tried two newlines.
To be clear, two empty lines means three newlines.
What does 'i' mean?
It should be the filename.
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.

1 Comment

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.