gnuplot:如何将图例放在多图中的每个图之外?

gnuplot: How to put legends outside of each plot in a multiplot?

我想把外面每个情节的图例放在上面。 我正在使用 multiplot ,所以问题是当我尝试这样做时,所有图例最终都出现在图的顶部。 如何将每个图例放在相应图的顶部? 她的是我的代码示例


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,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"

### 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:(所需的边距和大小以及正确的键,但“手动”设置)