同種の図を複数配置するとき (tiledlayout)概要論文に載せられるような図を描きたいときの話. 同種の図をたくさんならべる場合,ひとつひとつ legend や colobar をつけるのはスペースの無駄であるし,軸目盛りの数字のせいでタイル間に余計な空白が生じてしまうことも. Axes オブジェクトには YAxisLocation や XAxisLocation というプロパティがあり,left, right, bottom, top と指定するか,重複する目盛りラベルを消してしまうことでタイル間の余白を詰めることができる. 時系列図Aclear close all %% 適当なデモデータ作成 N = 49; z = peaks(N); LW = 1; % linewidth %% figureの大きさ設定 fig = figure('Position',[100,100,540,800]); tile = tiledlayout(4,1); %% plot ax(1) = nexttile; p1 = plot(1:N,z(:,21:25), LineWidth=LW); grid on box on ax(2) = nexttile; plot(1:N,z(:,26:30), LineWidth=LW); grid on box on ax(3) = nexttile; plot(1:N,z(:,11:15), LineWidth=LW); grid on box on ax(4) = nexttile; plot(1:N,z(:,15:20), LineWidth=LW); grid on box on %% 調整 set(ax,FontName='Helvetica',FontSize=14); linkaxes(ax,'xy'); xlim(ax,[0,N+1]); ylim(ax,[-9,9]); ax(1).XAxisLocation = 'top'; ax(2).XAxis.TickLabels = ''; ax(3).XAxis.TickLabels = ''; xlabel(ax(4),'x-axis label (unit)', FontName='Helvetica', FontSize=16); ylabel(ax(1),'y-axis label (unit)', FontName='Helvetica', FontSize=16); legend(p1,["Line 1","Line 2","Line 3","Line 4","Line 5"], FontName='Helvetica', FontSize=16, NumColumns=3, Location='southeast'); %% 最後にタイルの間隔を短く tile.Padding = 'compact'; tile.TileSpacing = 'tight'; 時系列図B行・列ともに複数の図があって空いているスペースができる時は,そこに凡例を配置すると図を見た目を邪魔しない. clear close all %% 適当なデモデータ作成 N = 49; z = peaks(N); LW = 1; % linewidth %% figureの大きさ設定 fig = figure('Position',[100,100,800,400]); tile = tiledlayout(3,2); %% plot ax(1) = nexttile; p1 = plot(1:N,z(:,21:25), LineWidth=LW); grid on box on ax(2) = nexttile; plot(1:N,z(:,26:30), LineWidth=LW); grid on box on ax(3) = nexttile; plot(1:N,z(:,11:15), LineWidth=LW); grid on box on ax(4) = nexttile; plot(1:N,z(:,15:20), LineWidth=LW); grid on box on ax(5) = nexttile; plot(1:N,z(:,5:10), LineWidth=LW); grid on box on ax(6) = nexttile; legend(ax(6),p1,["Line 1","Line 2","Line 3","Line 4","Line 5"], FontName='Helvetica', FontSize=16, NumColumns=3, Location='northwest'); ax(6).Visible = 'off'; %% 調整 set(ax,FontName='Helvetica',FontSize=14); linkaxes(ax,'xy'); xlim(ax,[0,N+1]); ylim(ax,[-9,9]); ax(1).XAxisLocation = 'top'; ax(2).XAxisLocation = 'top'; ax(3).XAxis.TickLabels = ''; ax(4).XAxis.TickLabels = ''; ax(2).YAxisLocation = 'right'; ax(4).YAxisLocation = 'right'; xlabel(ax(5),'x-axis label (unit)', FontName='Helvetica', FontSize=16); ylabel(ax(3),'y-axis label (unit)', FontName='Helvetica', FontSize=16); %% 最後にタイルの間隔を短く tile.Padding = 'compact'; tile.TileSpacing = 'tight'; 空間分布図複数列複数行で同種の図を出してcolorbarなどが重複するとき. clear close all N = 49; rseed = rng('default'); %% Figure size fig = figure('Position',[100,300,600,400]); tile = tiledlayout(2,3); %% plot ax(1) = nexttile; p1 = pcolor(rand(N)); shading flat axis equal tight colormap(ax(1),"parula"); ax(2) = nexttile; p2 = pcolor(rand(N)); shading flat axis equal tight colormap(ax(2),"parula"); ax(3) = nexttile; p3 = pcolor(rand(N)); shading flat axis equal tight colormap(ax(3),"parula"); cb3 = colorbar(ax(3),"eastoutside"); title(cb3,'m'); ax(4) = nexttile; p4 = pcolor(randn(N)); shading flat axis equal tight colormap(ax(4),"turbo"); ax(5) = nexttile; p5 = pcolor(randn(N)); shading flat axis equal tight colormap(ax(5),"turbo"); ax(6) = nexttile; colormap(ax(6),"turbo"); cb5 = colorbar(ax(6),"west"); title(cb5,'m'); %% 外観調整 set(ax,FontName='Helvetica',FontSize=14); linkaxes(ax,'xy'); xlim(ax,[0,N]); ylim(ax,[0,N]); clim(ax(1:3),[0,1]); clim(ax(4:6),[-1,1]); cb3.Ticks = 0.0:0.2:1.0; cb3.TickLabels = num2str(cb3.Ticks','%0.1f'); cb5.Ticks = -1.0:0.5:1.0; cb5.TickLabels = num2str(cb5.Ticks','%0.1f'); ax(1).XAxisLocation = 'top'; ax(2).XAxisLocation = 'top'; ax(3).XAxisLocation = 'top'; ax(2).YAxis.TickLabels = ''; ax(3).YAxis.TickLabels = ''; ax(5).YAxis.TickLabels = ''; ax(6).YAxis.TickLabels = ''; ax(6).Visible = 'off'; tile.Padding = 'compact'; tile.TileSpacing = 'tight'; より無駄のないように,上のcolorbarを空いているスペースにおくことも. cb5.Position = [cb5.Position(1)+0.05, cb5.Position(2:3), 0.9*cb5.Position(4)]; cb3.Position = [cb5.Position(1)+0.10, cb5.Position(2:4)]; |