gnuplot X轴的附加参数

gnuplot X轴的附加参数,gnuplot,Gnuplot,我想知道如何为每个X参数添加一个参数。如图所示,每个X参数都有一个附加参数 我使用以下命令运行gnuplot gnuplot -p -e "reset; set yrange [0:1]; set term png truecolor size 1024,1024; set grid ytics; set grid xtics; set key bottom right; set output 'Recall.png'; set key autotitle columnhead; plot

我想知道如何为每个X参数添加一个参数。如图所示,每个X参数都有一个附加参数

我使用以下命令运行gnuplot

gnuplot -p -e "reset; set yrange [0:1]; set term png truecolor size 1024,1024; set grid ytics; set grid xtics; set key bottom right; set output 'Recall.png'; set key autotitle columnhead; plot  for [i=2:3] 'Recall' using 1:i with linespoints linecolor i pt 0 ps 3
召回文件包含以下内容

train   approach1      approach2
2       0.6      0.07
7       0.64      0.076
9       0.65      0.078
我想知道是否可以添加以下附加参数

train   approach1      approach2
2(10)       0.6      0.07
7(15)       0.64      0.076
9(20)       0.65      0.078

实际绘图应根据实际X参数(2,7,9)进行。附加参数仅用于可视化,应与X一起打印。

许多
gnuplot
的终端提供了一个
增强的
选项
它模仿postscript提供的功能
终端,功能

您可以使用增强型终端和
set xtics
命令(有关正确的sintax,请参阅
help set xtics
):

有关可用命令的完整说明,请参阅链接

更新 要自动生成x轴标签,可以直接在gnuplot命令文件中或在命令行中使用反标记替换,如OP方法

命令行很长

gnuplot -p -e "reset; set yrange [0:1]; set term png truecolor size 1024,1024; set grid ; set key bottom right; set output 'Recall.png'; set key autotitle columnhead; `awk -f Recall.awk Recall` ; plot  for [i=2:3] 'Recall' using 1:i with linespoints linecolor i pt 0 ps 3"
关键点是使用一个输出适当gnuplot命令的awk脚本,这里就是awk脚本

% cat Recall.awk
BEGIN { printf "set xtics (" }
NR>1  { 
    printf (NR==2?"":",")
    printf ("'{/=8 %d} {/=16 (%d)}' %d", $1, $4, $1) }
END   { print ")"}
哎呀! 我忘了显示修改后的数据文件格式

% cat Recall
train   approach1      approach2 
2       0.6        0.07   10
7       0.64      0.076   15
9       0.65      0.078   20
这里它是上一个命令行的产物


如果要从数据文件中获取xtic标签,可以使用
使用…:xtic(1)
将第一列的值作为xtic标签

缺点可能是,对于数据文件中的每个值,都会得到一个xtic,而没有其他值。因此,使用数据文件

train   approach1      approach2
2(10)       0.6      0.07
7(15)       0.64      0.076
9(20)       0.65      0.078
你可以和我一起策划

reset
set term png truecolor size 1024,1024
set grid ytics
set grid xtics
set key bottom right
set output 'Recall.png'
set key autotitle columnhead
plot for [i=2:3] 'Recall' using 1:i:xtic(1) with linespoints linecolor i pt 7 ps 3
得到

请注意,这只使用正确的x值,因为gnuplot本身会将内容放在括号内,而不是有效的数字

如果要为标签部件使用不同的字体大小,可以添加包含参数的附加列

数据文件
Recall2

train   add       approach1      approach2
2       (10)      0.6       0.07
7       (15)      0.64      0.076
9       (20)      0.65      0.078
现在,除了使用
xtic(1)
,您还可以构造用作xticlabel的字符串:

reset
set term pngcairo truecolor enhance size 1024,1024
set grid ytics
set grid xtics
set key bottom right
set output 'Recall2.png'
set key autotitle columnhead
myxtic(a, b) = sprintf("{%s}{/*1.5 %s}", a, b)
plot for [i=3:4] 'Recall2' using 1:i:xtic(myxtic(strcol(1), strcol(2))) with linespoints linecolor i pt 7 ps 3

非常感谢您的回答,问题是我还是gnuplot的新手,我添加了一个代码,如果您有机会,请您看一下附录,并给出一个提示,如何实现我想要的参数。我已经看了您的附录,不,目前我不知道如何从数据内容设置
xtics
。顺便说一句,你的方法行不通:我会开始使用4列,如
20.60.0710
,但我必须考虑是否有可能做到你想要的。。。如果我能想出一个解决办法,我会更新我的答案
reset
set term pngcairo truecolor enhance size 1024,1024
set grid ytics
set grid xtics
set key bottom right
set output 'Recall2.png'
set key autotitle columnhead
myxtic(a, b) = sprintf("{%s}{/*1.5 %s}", a, b)
plot for [i=3:4] 'Recall2' using 1:i:xtic(myxtic(strcol(1), strcol(2))) with linespoints linecolor i pt 7 ps 3