如何在gnuplot中使用列标题设置轴标签? [英] How do I set axis label with column header in gnuplot?
问题描述
我的问题很简单.假设我有一个带有列标题的数据文件,如下所示
My question is very simple. Suppose I have a datafile with column headers, like as follows
first second
1 1
2 1
3 6
4 9
在gnuplot中,我如何做到这一点,以便使用列标题作为轴标签来绘制数据文件?例如通过致电
In gnuplot how do i make it so that the datafile is plotted using the column header as axis label? e.g. by calling
plot datafile using 1:2
我得到标为first
的xaxis和标为second
的yaxis?
i get the xaxis labeled first
and the yaxis labeled second
?
我确实知道可以通过set key auto title column head
将列标题用作键条目,但这并不是我想要的.
edit: I do know that I can use the column header as a key entry via set key auto title column head
, however that's not quite what I'm looking for.
推荐答案
要详细说明@andyras的建议,请按以下步骤操作:
To elaborate the suggestion of @andyras, here is how you can do it:
datafile = 'filename.txt'
firstrow = system('head -1 '.datafile)
set xlabel word(firstrow, 1)
set ylabel word(firstrow, 2)
plot datafile using 1:2
您必须使用显式的using
语句进行绘图,否则gnuplot会抱怨bad data on line 1
.
You must plot with the explicit using
statement, otherwise gnuplot will complain about bad data on line 1
.
这篇关于如何在gnuplot中使用列标题设置轴标签?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!