Help fixing different sized plots with tiled layout
66 views (last 30 days)
Show older comments
Manuel Santana
on 20 Dec 2024 at 20:52
I am trying to make a 3 x 3 tiled layout of wide rectangles, each of which has a title. However when I try this, (minimal example below) the top three figures appear slightly smaller than the bottom figures. The question is how do we fix this? I am aware that subplot does not have this issue, however subplot has too much white space between the figures for my purposes. Also I know that if I take the titles out, the figures are all the same size, but I need all the titles to be there.
figure(3);
clf
tiledlayout(3,3,"TileSpacing","compact","Padding","compact");
xlims = [-13,3];
ylims = [-3,3];
for ii = 1:9
to_plot = zeros(410,170);
nexttile
% subplot(3,3,ii) % Gets rid of the problem, but leaves too much white
% space.
ax = gca;
hold on
imagesc(xlims,ylims,to_plot,'Interpolation','bilinear')
shading interp;
colormap("jet")
title(ax, "$t = " + num2str(ii) + "$",'interpreter','latex','fontsize',15)
hold off
axis equal
axis off
end
2 Comments
Cris LaPierre
on 20 Dec 2024 at 21:47
Edited: Cris LaPierre
on 20 Dec 2024 at 21:48
I also see that. I can get it to go away if I remove either the 'axis equal' or the title. That doesn't seem right, so I have reported it internally.
tiledlayout(3,3,"TileSpacing","compact","Padding","compact");
xlims = [-13,3];
ylims = [-3,3];
for ii = 1:9
to_plot = zeros(410,170);
nexttile
imagesc(xlims,ylims,to_plot)
title("$t = " + num2str(ii) + "$",'interpreter','latex','fontsize',15)
% axis equal
axis off
end
Accepted Answer
Matt J
on 21 Dec 2024 at 15:02
Edited: Matt J
on 21 Dec 2024 at 15:21
Since you use imagesc to generate the subfigures, it seems to me that you should be using axis image.
tiledlayout(3,3,"TileSpacing","compact","Padding","compact");
xlims = [-13,3];
ylims = [-3,3];
for ii = 1:9
to_plot = zeros(410,170);
ax(ii)=nexttile;
imagesc(xlims,ylims,to_plot,'Interpolation','bilinear')
shading interp;
colormap("jet")
title( "$t = " + ii + "$",'fontsize',15,'interpreter','latex')
axis off
axis image
end
pos_table =array2table( vertcat(ax.InnerPosition), VariableNames={'Left','Lower','Width','Height'}, RowNames=compose('t = %d',1:9))
0 Comments
More Answers (1)
Catalytic
on 22 Dec 2024 at 14:05
axis equal does not ensure that the plot box reserved for the image will fit around it tightly. For that, you must add axis tight
tiledlayout(3,3,"TileSpacing","compact","Padding","compact");
xlims = [-13,3];
ylims = [-3,3];
for ii = 1:9
to_plot = zeros(41,17);
ax(ii)=nexttile;
imagesc(xlims,ylims,to_plot,'Interpolation','bilinear')
axis off
axis equal; axis tight
shading interp;
colormap("jet")
title( "$t = " + ii + "$",'fontsize',15,'interpreter','latex')
end
0 Comments
See Also
Categories
Find more on Blue in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!