使用 subplot 画图添加标题后,标题会和图重合,不会自动调整图窗布局
技术分享
发布于 2025-07-18 09:37:48
查看 2过去319天
可使用 tightlayout() 函数。
使用 subplot 画图未添加 tightlayout() 函数时,代码如下:
using TyPlot
subplot(2, 1, 1)
x = LinRange(0, 10, 100);
y1 = sin.(x);
plot(x, y1)
title("First Subplot")
subplot(2, 1, 2)
y1 = cos.(x);
plot(x, y1)
title("Second Subplot")
sgt = sgtitle("Subplot Grid Title"; color="red");
sgt.set_fontsize(20)
运行结果如下:

使用 subplot 画图在代码末尾 添加 tightlayout() 时,代码如下:
using TyPlot
subplot(2, 1, 1)
x = LinRange(0, 10, 100);
y1 = sin.(x);
plot(x, y1)
title("First Subplot")
subplot(2, 1, 2)
y1 = cos.(x);
plot(x, y1)
title("Second Subplot")
sgt = sgtitle("Subplot Grid Title"; color="red");
sgt.set_fontsize(20)
tightlayout()
运行结果如下,可看到已自动调整标题与图表的间距:

说明:
-
tightlayout() 为当前图窗布局的自动调整功能,用于自动调整 Syslab 图窗中的子图边距和布局,以确保它们适合图形。主要用于 Syslab 绘图的布局优化。
-
tightlayout(fig) 设置指定图窗的布局自动调整功能,用于自动调整 Syslab 图窗中的子图边距和布局,以确保它们适合图形。主要用于 Syslab 绘图的布局优化。
-
更多说明可在帮助文档中搜索 tightlayout 。

所属专栏:Syslab基础平台
产品信息:Syslab科学计算环境