gnuplot: date and time in separate columns for x axis, sorting input file

gnuplot

Solution

With regards to using two column dates, you just tell Gnuplot about them, e.g.:

set xdata time
set timefmt "%Y-%m-%d %H:%M:%S"
set format x "%m/%d\n%H:%M"
plot 'all.dat' using 1:3 with lines

Results in:

Depending on your shell the asterisk (`*`) will list files in lexicographical order, so you should be okay. However, there are easy ways around it if the output is unsorted, e.g. add sort to the plot command:

plot '<sort all.dat' using 1:3 with lines

Results in:

Problem

Let me set the stage in order: Previously I was plotting only for a single day (today.dat) that looks like this: ``` 2017-05-02 12:00:25 24.5 2017-05-02 12:01:26 25.2 2017-05-02 12:02:27 29.2 ``` so I just used column 2, with this program (minus the limit lines for brevity) and output: ``` set title "24V PV Battery Bank" set xlabel "Time" set ylabel "Volts" set grid unset mouse unset log unset key set timestamp set xdata time set timefmt '%H:%M:%S' set xticks format '%H:%M' plot "today.dat" using 2:$3 with lines lc rgb 'red' t 'battery' ``` Then at midnight each night I copy today.dat into an Archive directory with each file named by the date, like 2017-05-02.dat, 2017-05-03.dat, etc... So far, so good. ...but now I have concatenated all those daily files into all.dat ``` cat Archive/*.dat >all.dat ``` which looks like this: ``` 2017-05-02 12:00:25 24.5 2017-05-02 12:01:26 25.2 2017-05-02 12:02:27 29.2 2017-05-02 15:00:12 29.2 2017-05-04 12:01:32 24.7 2017-05-04 12:02:35 24.7 2017-05-04 12:03:37 24.7 2017-05-03 12:00:45 24.6 2017-05-03 12:01:46 24.6 2017-05-03 12:02:47 24.7 ``` So I need to know how to use both columns 1 and 2 in the x-axis. Also, since I don't know how cat works on whole directories full of the daily files, I am not sure they have concatenated in sequential days, so maybe will need to be able to sort all.dat? Questions: 1) How do I put the original columns 1 and 2 together as the x-axis? (Even if it takes running a pre-processing program to do so, then so be it) 2) How do I sort the file on two tab-delimited columns to make sure they are sequential. Many thanks in advance.

Original source