Search code examples
gnuplot

Equal frame size in a multiplot 3x4


I have the following multiplot

set encoding iso_8859_1


set xtics font "Helvetica,16"
set ytics font "Helvetica,16"

set terminal postscript eps enhanced color size 12in,6in
set grid

set key box vertical width 2 height 0.75 maxcols 1 #spacing 1
load "../estilos.txt"

# TMARGIN = "set tmargin at screen 0.90; set bmargin at screen 0.55"
# BMARGIN = "set tmargin at screen 0.55; set bmargin at screen 0.20"
# LMARGIN = "set lmargin at screen 0.15; set rmargin at screen 0.55"
# RMARGIN = "set lmargin at screen 0.55; set rmargin at screen 0.95"
############################################################################################
set output "_Mult_16R_4Chk_mp.eps"

set title "Minimum number of contention intervals, {/Symbol D}=1" font "Helvetica,17"

set multiplot layout 3,4 columnsfirst
set xlabel ""
set ylabel "T [s]" font "Helvetica,19"
set key top left font "Helvetica,16" 
# @TMARGIN @LMARGIN
plot [0:40][0:140] "contention_1/sys-time-4-16-80-15-2.txt" u ($1/60):2 every 2  ls 20   ps 0.35  title "MSL=80%"

set title ""
set key top left font "Helvetica,16" 
set ylabel "Queue length [batches]" font "Helvetica,19"
# @BMARGIN; @LMARGIN
plot [0:40][0:70] "contention_1/queue-length-4-16-50-15-1.txt"  using ($1/60):2 every 2 with lines  ls 20    lw 1.5   title "MSL=50%" ,\
                  "contention_1/queue-length-4-16-80-15-2.txt" using  ($1/60):2  every 2 with lines  ls 2200  lw 1.5   title "MSL=80%" ,\
                  "contention_1/queue-length-4-16-98-15-3.txt" using  ($1/60):2  every 2 with lines  ls 5550  lw 1.5   title "MSL=98%"

set key bottom right font "Helvetica,16" 
set ylabel "Inventory ratio, {/Symbol g}" font "Helvetica,19"  
set xlabel "Operation time [minutes]" font "Helvetica,19"

# @BMARGIN; @LMARGIN
plot [0:40][0:1] "contention_1/known-ratio-4-16-50-15-1.txt"  using ($1/60):2 every 2 w linespoints  ls 20   ps 0.75 lw 1.5    title "MSL=50%" ,\
                 "contention_1/known-ratio-4-16-80-15-2.txt" using  ($1/60):2  every 2 w linespoints  ls 2200 ps 0.75 lw 1.5       title "MSL=80%" ,\
                 "contention_1/known-ratio-4-16-98-15-3.txt" using  ($1/60):2  every 2 w linespoints  ls 5550 ps 0.75 lw 1.5         title "MSL=98%"

############################################################################################

set title "Minimum number of contention intervals, {/Symbol D}=100" font "Helvetica,17"

set xlabel ""
set ylabel ""
set key top left font "Helvetica,16" 
plot [0:40][0:140] "contention_100/sys-time-4-16-80-15-2.txt" u ($1/60):2 every 2  ls 20   ps 0.35  title "MSL=80%"

set title ""
set key top left font "Helvetica,16" 
plot [0:40][0:70] "contention_100/queue-length-4-16-50-15-1.txt"  using ($1/60):2 every 2 with lines  ls 20    lw 1.5   title "MSL=50%" ,\
                  "contention_100/queue-length-4-16-80-15-2.txt" using  ($1/60):2  every 2 with lines  ls 2200  lw 1.5   title "MSL=80%" ,\
                  "contention_100/queue-length-4-16-98-15-3.txt" using  ($1/60):2  every 2 with lines  ls 5550  lw 1.5   title "MSL=98%"

set key bottom right font "Helvetica,16" 
set xlabel "Operation time [minutes]" font "Helvetica,19"


plot [0:40][0:1] "contention_100/known-ratio-4-16-50-15-1.txt"  using ($1/60):2 every 2 w linespoints  ls 20   ps 0.75 lw 1.5    title "MSL=50%" ,\
                 "contention_100/known-ratio-4-16-80-15-2.txt" using  ($1/60):2  every 2 w linespoints  ls 2200 ps 0.75 lw 1.5       title "MSL=80%" ,\
                 "contention_100/known-ratio-4-16-98-15-3.txt" using  ($1/60):2  every 2 w linespoints  ls 5550 ps 0.75 lw 1.5         title "MSL=98%"

############################################################################################

set title "Minimum number of contention intervals, {/Symbol D}=200" font "Helvetica,17"

set xlabel ""
set ylabel ""
set key top left font "Helvetica,16" 
plot [0:40][0:140] "contention_200/sys-time-4-16-80-15-2.txt" u ($1/60):2 every 2  ls 20   ps 0.35  title "MSL=80%"

set title ""
set key top left font "Helvetica,16" 
plot [0:40][0:70] "contention_200/queue-length-4-16-50-15-1.txt"  using ($1/60):2 every 2 with lines  ls 20    lw 1.5   title "MSL=50%" ,\
                  "contention_200/queue-length-4-16-80-15-2.txt" using  ($1/60):2  every 2 with lines  ls 2200  lw 1.5   title "MSL=80%" ,\
                  "contention_200/queue-length-4-16-98-15-3.txt" using  ($1/60):2  every 2 with lines  ls 5550  lw 1.5   title "MSL=98%"

set key bottom right font "Helvetica,16" 
set xlabel "Operation time [minutes]" font "Helvetica,19"


plot [0:40][0:1] "contention_200/known-ratio-4-16-50-15-1.txt"  using ($1/60):2 every 2 w linespoints  ls 20   ps 0.75 lw 1.5    title "MSL=50%" ,\
                 "contention_200/known-ratio-4-16-80-15-2.txt" using  ($1/60):2  every 2 w linespoints  ls 2200 ps 0.75 lw 1.5       title "MSL=80%" ,\
                 "contention_200/known-ratio-4-16-98-15-3.txt" using  ($1/60):2  every 2 w linespoints  ls 5550 ps 0.75 lw 1.5         title "MSL=98%"

############################################################################################

set title "Minimum number of contention intervals, {/Symbol D}=300" font "Helvetica,17"

set xlabel ""
set ylabel ""
# set ylabel "T [s]" font "Helvetica,19"
set key top left font "Helvetica,16" 
plot [0:40][0:140] "contention_300/sys-time-4-16-80-15-300-2.txt" u ($1/60):2 every 2  ls 20   ps 0.35  title "MSL=80%"

set title ""
set key top left font "Helvetica,16" 
plot [0:40][0:70] "contention_300/queue-length-4-16-50-15-300-1.txt"  using ($1/60):2 every 2 with lines  ls 20    lw 1.5   title "MSL=50%" ,\
                  "contention_300/queue-length-4-16-80-15-300-2.txt" using  ($1/60):2  every 2 with lines  ls 2200  lw 1.5   title "MSL=80%" ,\
                  "contention_300/queue-length-4-16-98-15-300-3.txt" using  ($1/60):2  every 2 with lines  ls 5550  lw 1.5   title "MSL=98%"

set key bottom right font "Helvetica,16" 
set xlabel "Operation time [minutes]" font "Helvetica,19"


plot [0:40][0:1] "contention_300/known-ratio-4-16-50-15-300-1.txt"  using ($1/60):2 every 2 w linespoints  ls 20   ps 0.75 lw 1.5    title "MSL=50%" ,\
                 "contention_300/known-ratio-4-16-80-15-300-2.txt" using  ($1/60):2  every 2 w linespoints  ls 2200 ps 0.75 lw 1.5       title "MSL=80%" ,\
                 "contention_300/known-ratio-4-16-98-15-300-3.txt" using  ($1/60):2  every 2 w linespoints  ls 5550 ps 0.75 lw 1.5  title "MSL=98%"

unset multiplot

The data files are linked here.

The plot looks like this:

enter image description here

which has the information I want to show.

However, the frames are not equal in size. For example, the first row is shorter because it has titles, the middle row of plots is bigger, and the bottom row is also small. The widths of single plots are differents too.

I have seen in this post of Gnuplotting Multiplot – placing graphs next to each other that using set l/b/r/tmargin at screen value is the way to set the sizes of the frames in a multiplot 2x2, but in my case multiplot 3x4 and with tics and separation between single plots result more difficult to achieve.


Solution

  • To my opinion, you probably should forget about set multiplot layout 3,4. Instead, set the sizes and origins of the plots yourself and insert the titles and xlabels as labels at the top and at the bottom. Then use a few parameters to tune your layout. If the code might not be self-explaining enough do not hesitate to ask.

    Code:

    ### customized multiplot
    reset session
    
    # Parameters to tune
    PlotRows = 3
    PlotCols = 4
    TitlePosY = 0.98
    MultiPlotTop = 0.93
    SizeScalingX = 0.90
    SizeScalingY = 0.95
    MultiPlotBottom = 0.05
    XLabelPosY = 0.03
    MultiPlotLeft = 0.07
    YLabelPosX = 0.02
    set lmargin 2
    
    # define origin functions
    PlotGridX = (1-MultiPlotLeft)/PlotCols
    PlotOriginX(n) = ((n-1)%PlotCols)*PlotGridX + MultiPlotLeft
    PlotGridY = (MultiPlotTop-MultiPlotBottom)/PlotRows
    PlotOriginY(n) = (PlotRows-1-int((n-1)/PlotCols))*PlotGridY + MultiPlotBottom
    
    # set size
        set size SizeScalingX*(1-MultiPlotLeft)/PlotCols, SizeScalingY*(MultiPlotTop+MultiPlotBottom)/PlotRows
    
    # set your titles and labels
    TitleStd = "Minimum number of \ncontention intervals, {/Symbol D}="
    TitleVar = "1 100 200 300"
    XLabelStd = "Operation time [minutes]"
    do for [i=1:PlotCols] {
        set label i at screen PlotOriginX(i), screen TitlePosY TitleStd.word(TitleVar,i) font "Helvetica,8"
        set label i+10 at screen PlotOriginX(i), screen XLabelPosY XLabelStd font "Helvetica,8"
    }
    YLabels = '"T [s]" "Queue length [batches]" "Inventory ratio, {/Symbol g}"'
    do for [i=1:PlotRows] {
        set label i+20 at screen YLabelPosX, screen PlotOriginY(i*PlotCols)+PlotGridY*0.5 word(YLabels,i) rotate by 90 center
    }
    
    set multiplot
        do for [i=1:12] {   # do your 3x4 plots here and increase "counter" i after each plot
            set origin PlotOriginX(i), PlotOriginY(i)
            plot 10**((i-1)/4)*sin(0.1*i*x) notitle
        }
    unset multiplot
    ### end of code
    

    Result:

    ls