如何在文件行号暗示 x 轴的同一图上绘制两列数据(使用 gnuplot)
how can I plot two colums of data on the same plot where the x axis is implied by the file row number (using gnuplot)
我有包含两列数字的文本文件,我将它们称为 col1 和 col2。我可以使用 gnuplot 绘制 col2 与 col1 或反之亦然,但我无法弄清楚如何将 col1 和 col2(即覆盖两列数据)绘制为文件中行号的函数(即,x 轴由文件行编号隐式给出)。我想我可以在第一列中插入一个行号,但我猜想在 gnuplot 中有一种更简单的方法可以做到这一点。在 linux 中,我可以使用“cat -n”来输出一个三列文件,但我正试图在 Windows 系统上为朋友执行此操作,但我不知道 Windows 有类似于猫的东西。
谢谢!
使用列索引 0 作为行号:
plot "file" using 0:1, "" using 0:2
仅作记录。无论您认为是行号...
在大多数情况下,伪列 0(检查 help pseudocolumns
)将完成这项工作。但是,如果数据中有双空行,情况就会有所不同,因为伪列 0 将重置为 0
。
检查以下示例以说明伪列 0 与另一种自己计算行数的方法之间的区别。
代码:
### plotting data versus "line number"
reset session
$Data <<EOD
1 21
2 22
3 23
5 24
6 25
7 26
10 27
11 28
12 29
EOD
set multiplot layout 1,2
plot $Data u 0:2 w lp pt 7
plot n=0 $Data u (n=n+1):2 w lp pt 7
unset multiplot
### end of code
结果:
我有包含两列数字的文本文件,我将它们称为 col1 和 col2。我可以使用 gnuplot 绘制 col2 与 col1 或反之亦然,但我无法弄清楚如何将 col1 和 col2(即覆盖两列数据)绘制为文件中行号的函数(即,x 轴由文件行编号隐式给出)。我想我可以在第一列中插入一个行号,但我猜想在 gnuplot 中有一种更简单的方法可以做到这一点。在 linux 中,我可以使用“cat -n”来输出一个三列文件,但我正试图在 Windows 系统上为朋友执行此操作,但我不知道 Windows 有类似于猫的东西。
谢谢!
使用列索引 0 作为行号:
plot "file" using 0:1, "" using 0:2
仅作记录。无论您认为是行号...
在大多数情况下,伪列 0(检查 help pseudocolumns
)将完成这项工作。但是,如果数据中有双空行,情况就会有所不同,因为伪列 0 将重置为 0
。
检查以下示例以说明伪列 0 与另一种自己计算行数的方法之间的区别。
代码:
### plotting data versus "line number"
reset session
$Data <<EOD
1 21
2 22
3 23
5 24
6 25
7 26
10 27
11 28
12 29
EOD
set multiplot layout 1,2
plot $Data u 0:2 w lp pt 7
plot n=0 $Data u (n=n+1):2 w lp pt 7
unset multiplot
### end of code
结果: