自动标题任意块数
Automatically Title Arbitrary Number of Blocks
我想分别绘制文件中的各个块。我发现这行得通:
$ cat test
A
0 0
1 1
B
0 0
1 2
C
0 0
1 3
然后
gnuplot> plot for [i=0:2] 'test' index i with lines title columnhead
给我三个单独的行,分别标记为 A、B、C。完美。
但是我不知道文件中的块数,所以我遇到了问题。 This answer 建议使用 stats
获取文件中的块数,但 stats
失败并显示 bad data on line 6
(第二个块的标题 "B") .
我可以控制输入文件,因此我可以根据需要设置不同的格式。
如何使用自动标题绘制任意数量的块(单独)?
对于 gnuplot 5.0 版,您可以在调用 stats
之前使用 set key autotitle columnheader
:
set key autotitle columnheader
stats 'test'
set style data lines
plot for [i=0:STATS_blocks-1] 'test' index i
这不适用于 4.6 及更早版本。在这里,您可以使用 grep
等外部工具来过滤传递给 stats
的数据。要删除所有不以数字开头或不为空的行,可以使用
stats '< grep -v "^[^0-9]" test'
或
stats '< grep ''\(^[0-9]\)\|\(^$\)'' test'
判断数据集的个数,存储在变量STATS_blocks
.
我想分别绘制文件中的各个块。我发现这行得通:
$ cat test
A
0 0
1 1
B
0 0
1 2
C
0 0
1 3
然后
gnuplot> plot for [i=0:2] 'test' index i with lines title columnhead
给我三个单独的行,分别标记为 A、B、C。完美。
但是我不知道文件中的块数,所以我遇到了问题。 This answer 建议使用 stats
获取文件中的块数,但 stats
失败并显示 bad data on line 6
(第二个块的标题 "B") .
我可以控制输入文件,因此我可以根据需要设置不同的格式。
如何使用自动标题绘制任意数量的块(单独)?
对于 gnuplot 5.0 版,您可以在调用 stats
之前使用 set key autotitle columnheader
:
set key autotitle columnheader
stats 'test'
set style data lines
plot for [i=0:STATS_blocks-1] 'test' index i
这不适用于 4.6 及更早版本。在这里,您可以使用 grep
等外部工具来过滤传递给 stats
的数据。要删除所有不以数字开头或不为空的行,可以使用
stats '< grep -v "^[^0-9]" test'
或
stats '< grep ''\(^[0-9]\)\|\(^$\)'' test'
判断数据集的个数,存储在变量STATS_blocks
.