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

标签 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 复制到一个存档目录中,每个文件都以日期命名,例如 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 进行排序?

问题:

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

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

提前谢谢了。

最佳答案

关于使用两列日期,您只需将它们告诉 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 all.dat' using 1:3 with lines

结果是:

Result of sorted plot

关于gnuplot:日期和时间在 x 轴的单独列中,对输入文件进行排序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43924462/

相关文章:

在 gnuplot 中的列上绘制具有条件的数据集

label - gnuplot 标签中可以有多种颜色吗?

gnuplot - 秤测量数据

gnuplot - Gnuplot 5.0 中 dashtype 索引的确切含义?

gnuplot - 使用pointinterval减少点数

c++ - 使用 GNU Plot 绘制复杂函数

gnuplot - 如何用 Gnuplot 演示 LaTeX 公式?

Ubuntu - gnuplot 重新读取取消选择的文本

gnuplot - 多个绘图文件使用相同的样式设置,但绘图线的数量不同?

Gnuplot:设置第三个(彩色)点的范围