在Gnuplot 5.2中,您可以使用plot "datafile" ... title columnheader(1)
在数据文件中首先显示字符串作为键。但是,当您尝试附加类似plot "datafile" ... title columnheader(1) . "X"
中的字符串时,它以unexpected ot unrecognized token
失败。
但是,当我使用plot "datafile" ... title columnhead(1) . "X"
时,它会起作用!
那么columnheader(N)
和columnhead(N)
之间有什么区别,为什么两者都存在?
答案 0 :(得分:1)
帮助文本试图解释这一点。 columnhead(x)
是一个字符串值函数。因此,它可以与其他功能组合或组合。
gnuplot> help columnhead
`columnhead(x)` may only be used as part of a plot, splot, or stats command.
It evaluates to a string containing the content of column x in the first line
of a data file. See `plot datafile using`.
请注意,此功能可以在plot命令中的任何位置使用,而不仅仅是标题选项。例如:
plot DATA using 1:2:(columnhead(3)) with labels
相比之下,关键字columnheader
仅作为标题选项有效。常见用法是set key
命令的一种选择,形式为
set key autotitle columnheader
它将影响从数据文件生成的所有绘图组件(与功能相反)。为方便起见,也可以将其用作单个情节组件的标题替代,如
plot DAT1 using 1 title "foo", DAT2 using 2 title "baz", DAT3 using 3 title columnheader
这样做的一个缺点是程序必须猜测是哪一列。在上面的示例中它是明确的,但是请考虑:
plot DAT3 using ($2+$3)/($4) title columnheader # _which_ columnheader?
因此,在特殊情况下,程序将查看括号中的特定列是否紧随关键字之后。即它看起来像一个函数,但实际上不是。该程序可能更聪明,并且意识到它可以使用实际的功能columnhead()
,但不幸的是,它并不那么聪明。