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

时间:2017-05-11 19:56:39

标签: 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

所以我只使用了第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'

enter image description here

然后每晚午夜我将today.dat复制到Archive目录中,每个文件都按日期命名,如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    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进行排序? / p>

问题:

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

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

非常感谢提前。

2 个答案:

答案 0 :(得分:3)

关于使用两个列日期,您只需告诉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

结果:

Result of unsorted plot

根据您的shell,星号(*)将按字典顺序列出文件,因此您应该没问题。但是,如果输出未排序,例如,有很简单的方法。在plot命令中添加sort:

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

结果:

Result of sorted plot

答案 1 :(得分:2)

使用awk格式化数据。在这里,我们将2017-05-02_12:00:25 24.5传递给sort命令的字符串。 awk打印第一列和第二列,以“_”分隔,后跟第三列。这些字符串被排序并重定向到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

enter image description here