Building multiple episodes from a file using Gnuplot

I have a form data file:

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 

What I would like to build as a series of series on the same plot using gnuplot, but I am new to gnuplot, and I can’t understand how using should be structured here.

I would like to build column 2, date / time, as the X axis with column 3, as the Y axis, with subsequent sections. Is it possible? Is the X axis not always in the first column?

I tried:

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

But the error turned out:

 x range is invalid 

Can someone show me where I'm wrong?

+4
source share
2 answers

To plot a date / time graph along the x axis, you need set xdata time . Then you need to specify gnuplot in what format date / time data. In your case

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

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

You might want to set the format on which the x axis should be displayed. In your case it’s possible

 set format x "%H:%M" 

will make sense.

I was unable to build your data with quotes around a 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 script:

 set xdata time set timefmt "%d-%b-%Y %H:%M" set format x "%H:%M" plot "Data.csv" u 2:4 wl 

you should get it

enter image description here

result.

+7
source

@Woltan answer extension: if you want each section to have a different color / style, use index (but then you need to split the sections into two lines emtpy):

 plot 'i' index 0 using 2:4 with lines, '' index 1 using 2:4 with lines 
+10
source

Source: https://habr.com/ru/post/1386699/


All Articles