1
votes

I would like to put the legend of each plot outside on the top of them. I'm using multiplot ,so the problem is that when i try to do this all the legends end up at the top of the figure. How can I put each legend on top of the corresponding plots ? Hers is a sample of my code


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

And here is the image produced (by the complete code)

enter image description here

1
it looks like the key conflicts with margins 0.07, 0.95, 0.05, 0.97 (screen coordinates, not graph coordinates). Skip this and and you will have the key at each plot, however, not with the desired margins. Right away, I don't have a good solution. I will think about it. - theozh
Yes totally, I removed the margins and now it works fine - RIXS

1 Answers

0
votes

Check the following 3 variations of a minimal example.

  • Variation 1 has different sizes of the subplots, that's not what you wanted.
  • In variation 2, I would consider the behaviour of the key as unexpected and as a bug.
  • The third (cumbersome) variation probably comes close to what you expected.

Code:

### 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

Result 1: (undesired auto margins, i.e. different subplot sizes, but correct keys)

enter image description here

Result 2: (desired margins and equal subplot sizes, but wrong overlapping keys)

enter image description here

Result 3: (desired margins and sizes and correct keys, but "manual" settings)

enter image description here