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?
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
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
result.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With