我想知道如何为每个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一起打印。
答案 0 :(得分:2)
许多gnuplot
的终端提供enhanced
选项
模仿postscript提供的功能
终端,功能described here。
您可以使用增强型终端和set xtics
命令完成所需的操作(有关正确的sintax,请参阅help set xtics
):
gnuplot> set term qt enhanced
gnuplot> set xrange [2:10]
gnuplot> set xtics ('{/=8 3} {/=20 (a)}' 3, '6 (c)' 6)
gnuplot> plot sin(x)
请参阅链接以获取可用命令的完整说明。
要自动生成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"
关键是使用awk脚本输出相应的gnuplot命令,这里是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
这里它是上一个命令行的产物
答案 1 :(得分:1)
如果要从数据文件中获取xtic标签,可以使用using ...: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
现在,您还可以构造要用作xticlabel的字符串,而不是使用xtic(1)
:
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