gnuplot:x轴的日期和时间在单独的列中,对输入文件进行排序

gnuplot:x轴的日期和时间在单独的列中,对输入文件进行排序,gnuplot,Gnuplot,让我把舞台安排得井然有序: 以前,我只为一天(today.dat)绘制了如下图: 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 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

让我把舞台安排得井然有序:

以前,我只为一天(today.dat)绘制了如下图:

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    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
所以我只使用了第2列,这个程序(为了简洁起见减去限制行)和输出:

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'

然后在每晚午夜,我将today.dat复制到存档目录中,每个文件都以日期命名,如2017-05-02.dat、2017-05-03.dat等

到目前为止,一切顺利


…但现在我已将所有这些日常文件连接到all.dat中

cat Archive/*.dat >all.dat
看起来是这样的:

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    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
所以我需要知道如何使用x轴上的第1列和第2列

另外,由于我不知道cat如何处理包含每日文件的整个目录,所以我不确定它们是否在连续几天内连接在一起,所以可能需要能够对all.dat进行排序

问题:

1) 如何将原始列1和2放在一起作为x轴?(即使需要运行预处理程序才能做到这一点,那就这样吧)

2) 如何在两个制表符分隔的列上对文件进行排序,以确保它们是连续的


非常感谢。

使用
awk
格式化数据。在这里,我们可以通过管道将
2017-05-02_12:00:25 24.5
之类的字符串传输到
sort
命令
awk
打印第一列和第二列,第二列由“uu”分隔,第三列紧跟其后。这些字符串被排序并重定向到gnuplot

set xdata time
set timefmt '%Y-%m-%d_%H:%M:%S'
set format x "%m/%d\n%H:%M"
plot "<awk '{print $1\"_\"$2\" \"$3}' tm.dat |sort" u 1:2 w l
设置扩展数据时间
设置时间%Y-%m-%d\u%H:%m:%S
设置格式x“%m/%d\n%H:%m”

plot“

关于使用两列日期,您只需告诉Gnuplot它们,例如:

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
结果:

根据您的shell,星号(
*
)将按字典顺序列出文件,因此您应该没问题。但是,如果输出未排序,有一些简单的方法可以解决,例如,将排序添加到绘图命令:

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

plot'我喜欢你的答案。谢谢。它教会了我很多关于plot命令的文件名部分的内容。我最喜欢这个答案,因为它使用gnuplot来执行操作。谢谢。谢谢你的答案。很难只为accept选一个。