gnuplot - 多图中的行标题
问题描述
在下图中,每一行对应一个不同的案例/参数。参数从上到下依次为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
}
解决方案
也许最简单的方法是使用多行 y 标签:
set ylabel "nmesh-2\n\nElapsed time"
然而,这种解决方案的灵活性相当有限。作为替代方案,可以使用set multiplot
该margins
选项以确保在整个多图的全局左边距中有足够的“行标题”空间,手动计算屏幕坐标中各个“行标题”的坐标并在最后一个情节中渲染它们:
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
}
推荐阅读
- java - 在 Maven 项目中运行代码...找不到类
- error-handling - Django rest framework 3.10.3 没有运行异常处理程序
- c# - Web API XML反序列化:具有多个具有相同标签名称的子节点的节点
- automapper - 无法将 AutoMapper.Mapper.Map 方法与 ASP.NET Core 3.0 Web API 一起使用
- python - ModuleNotFoundError:QGIS 中没有名为“_tkinter”的模块
- r - 如何使用 facet_wrap 或 facet_grid 对绘图进行刻面?
- javascript - 清除 Javascript 中不需要的代码重复
- oracle - ORA-00907: 缺少右括号
- apache - 将 HTTP 重定向到 HTTPS 并添加 WWW
- python - 如何使用等于函数名称的字符串值调用函数