首页 > 解决方案 > 多图中的行标题

问题描述

在下图中,每一行对应一个不同的案例/参数。参数从上到下依次为nmesh-2, nmesh-4, nmesh-6, nmesh-8。我想将每个参数写在 ylabel 或Elapsed time. 换句话说,我想要一个“行标题”。如果参数名称大于并旋转为Elapsed time. 我的代码包含文件名,但如果我也包含它。

在此处输入图像描述

set key autotitle columnhead
set boxwidth 0.5
set style fill transparent solid
set nokey

set terminal wxt size 1900,990
set multiplot layout 4, 7
set xtics rotate by -45

np = "8 12 16 20 24 28 32"
do for [IDX=1:7] {
    if (IDX == 1) {
        set ylabel 'Elapsed time'
    }
    else {
        unset ylabel
    }
    set title sprintf("np-%s", word(np, IDX))
    plot sprintf("run-1/np-%s/nmesh-2/load-estim-0/hole-cut-implicit/cpupertask-3/ncell-11/dominant-0.dat", word(np, IDX)) u 2:xtic(1) with boxes
}
set notitle
do for [IDX=1:7] {
    if (IDX == 1) {
        set ylabel 'Elapsed time'
    }
    else {
        unset ylabel
    }
    plot sprintf("run-1/np-%s/nmesh-4/load-estim-0/hole-cut-implicit/cpupertask-3/ncell-11/dominant-0.dat", word(np, IDX)) u 2:xtic(1) with boxes
}
do for [IDX=1:7] {
    if (IDX == 1) {
        set ylabel 'Elapsed time'
    }
    else {
        unset ylabel
    }
    plot sprintf("run-1/np-%s/nmesh-6/load-estim-0/hole-cut-implicit/cpupertask-3/ncell-11/dominant-0.dat", word(np, IDX)) u 2:xtic(1) with boxes
}
do for [IDX=1:7] {
    if (IDX == 1) {
        set ylabel 'Elapsed time'
    }
    else {
        unset ylabel
    }
    plot sprintf("run-1/np-%s/nmesh-10/load-estim-0/hole-cut-implicit/cpupertask-3/ncell-11/dominant-0.dat", word(np, IDX)) u 2:xtic(1) with boxes
}

标签: gnuplot

解决方案


也许最简单的方法是使用多行 y 标签:

set ylabel "nmesh-2\n\nElapsed time"

然而,这种解决方案的灵活性相当有限。作为替代方案,可以使用set multiplotmargins选项以确保在整个多图的全局左边距中有足够的“行标题”空间,手动计算屏幕坐标中各个“行标题”的坐标并在最后一个情节中渲染它们:

set terminal pngcairo size 1900,990 enhanced
set output 'fig.png'

numOfRows = 4
marginLeft = 0.1
marginRight = marginLeft/2
marginV = 0.1
plotSpacing = marginV / 2
plotHeight = (1. - 2*marginV - (numOfRows-1)*plotSpacing) / numOfRows
labelPos(i) = 1. - (marginV + plotHeight/2 + i*(plotHeight + plotSpacing))

params = "nmesh-2 nmesh-4 nmesh-6 nmesh-8"

set multiplot layout numOfRows,7 margins marginLeft,1-marginRight,marginV,1-marginV spacing plotSpacing

set key autotitle columnhead
set boxwidth 0.5
set style fill transparent solid
set nokey

set xtics rotate by -45

np = "8 12 16 20 24 28 32"
do for [IDX=1:7] {
    if (IDX == 1) {
        set ylabel 'Elapsed time'
    }
    else {
        unset ylabel
    }
    set title sprintf("np-%s", word(np, IDX))
    plot sin(x) w l
}
set notitle
do for [IDX=1:7] {
    if (IDX == 1) {
        set ylabel 'Elapsed time'
    }
    else {
        unset ylabel
    }
    plot sin(x) w l
}
do for [IDX=1:7] {
    if (IDX == 1) {
        set ylabel 'Elapsed time'
    }
    else {
        unset ylabel
    }
    plot sin(x) w l
}


do for [IDX=1:7] {
    if (IDX == 1) {
        set ylabel "Elapsed time"
    }
    else {
        unset ylabel
    }

    if (IDX == 7) {
      do for [j=1:4] {
        set label word(params, j) at screen marginLeft/2, screen labelPos(j-1) offset char -2, 0 center rotate by 90 font "Arial,16"
      }
    }
    plot sin(x) w l
}

这应该产生: 在此处输入图像描述


推荐阅读