MATLAB/subplotで共通のタイトルを付ける

subplotでplot共通のタイトルを付けたいときがある.

MATLAB 2018b 以降ならsuptitleという関数があるので使ってみる.

f = peaks;
g = rand(100);


fig = figure;

subplot(121)
pcolor(peaks);shading flat
title('Title 1','FontName','Times')
set(gca,'FontName','Times')


subplot(122)
histogram(g)
title('Title 2','FontName','Times')
set(gca,'FontName','Times')

ti = suptitle('SuperTitle');
ti.FontSize = 12;
ti.FontName = 'Times';

 

suptitle(‘タイトル名’)で使えるが,Fontやサイズを指定するにはハンドルを取得して逐一変更する必要があった(suptitleに直接入力はできない).

 

 

因みに,R2018a以前ではsuptitleがないのでsgtitleを使う.下のスクリプトでも同じ図が出来上がる.

figure

subplot(121)
pcolor(peaks);shading flat
title('Title 1','FontName','Times')
set(gca,'FontName','Times')


subplot(122)
histogram(g)
title('Title 2','FontName','Times')
set(gca,'FontName','Times')

sgtitle('SuperTitle','FontName','Times')

 

参考サイト