如何解决gnuplot:如何将图例放在多图中的每个图之外?
我想把外面的每个情节的图例放在上面。 我正在使用 multiplot ,所以问题是当我尝试这样做时,所有的图例都出现在图的顶部。 如何将每个图例放在相应的图上? Hers 是我的代码示例
reset
set datafile separator comma
set term pdfcairo enhanced font "Helvetica,7" size 4,7
set output "data.pdf"
set multiplot layout 6,2 margins 0.07,0.95,0.05,0.97 spacing 0.1,0.05
set tics nomirror
set grid xtics ytics lt 1 lw 0.5 lc rgb "grey"
############################################ PLOT
set key outside horizontal
set ylabel "V [mV]"
set label "A" at graph -0.14,1.1
plot "data.txt" using "time":"V" with lines
unset label
plot "data.txt" using "time":"V" with lines
unset ylabel
############################################# PLOT
set key outside horizontal
set label "B" at graph -0.14,1.1
set ylabel "I_{tot} [pA/pF] "
plot "data.txt" using "time":"Itotal" with lines
unset ylabel
unset label
unset key
############################################ PLOT
set key outside horizontal
set label "G" at graph -0.16,1.1
set ylabel "J_{rel} [mM/s]"
plot "data.txt" using "time":"Jrel" with lines
unset ylabel
unset label
unset key
unset multiplot
解决方法
检查以下 3 个最小示例的变体。
- 变体 1 具有不同大小的子图,这不是您想要的。
- 在变体 2 中,我将密钥的行为视为意外和错误。
- 第三个(繁琐的)变体可能与您预期的很接近。
代码:
### multiplot version with undesired auto margins but correct keys
reset session
set key out horizontal
set multiplot layout 3,3 spacing 0.1,0.1
do for [i=1:9] {
plot x**i title sprintf("x**%d",i) lc i
}
unset multiplot
pause -1 "Press Enter to continue"
### multiplot version with desired margins but wrong keys
reset session
set key out horizontal
set multiplot layout 3,3 margin 0.07,0.93,0.07,0.93 spacing 0.1,i) lc i
}
unset multiplot
pause -1 "Press Enter to continue"
### version with desired margins and correct keys (but cumbersome)
reset session
set key out horizontal
myLmargin = 0.07
myRmargin = 0.93
myBmargin = 0.07
myTmargin = 0.93
myXspacing = 0.1
myYspacing = 0.1
Rows=3 # rows
Cols=3 # columns
myWidth = (myRmargin-myLmargin-(Cols-1)*myXspacing)*1./Cols
myHeight = (myTmargin-myBmargin-(Rows-1)*myYspacing)*1./Rows
# myPosX(n) = myLmargin + n*(myWidth + myXspacing)
# myPosY(m) = myTmargin - (row+1)*myHeight - 0.5*myYspacing
myLmarg(row,col) = myLmargin + col*(myWidth + myXspacing)
myRmarg(row,col) = myLmargin + (col+1)*myWidth + col*myXspacing
myBmarg(row,col) = myTmargin - (row+1)*myHeight - row*myYspacing
myTmarg(row,col) = myTmargin - row*(myHeight + myYspacing)
set multiplot
do for [row=0:Rows-1] {
do for [col=0:Cols-1] {
set origin myLmarg(row,col),myBmarg(row,col)-0.5*myYspacing
set size 1,1./Rows
set lmargin screen myLmarg(row,col)
set rmargin screen myRmarg(row,col)
set bmargin screen myBmarg(row,col)
set tmargin screen myTmarg(row,col)
j = row*Cols + col + 1
plot x**j title sprintf("x**%d",j) lc j
}
}
unset multiplot
### end of code
结果 1:(不需要的自动边距,即不同的子图大小,但正确的键)
结果 2:(所需的边距和相同的子图大小,但错误的重叠键)
结果 3:(所需的边距和大小以及正确的键,但“手动”设置)
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。