Help fixing different sized plots with tiled layout

46 visualizzazioni (ultimi 30 giorni)
Manuel Santana
Manuel Santana il 20 Dic 2024 alle 20:52
Modificato: Matt J circa 21 ore fa
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 Commenti
Cris LaPierre
Cris LaPierre 17 minuti fa
Modificato: Cris LaPierre 16 minuti fa
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

Accedi per commentare.

Risposte (2)

Matt J
Matt J circa 7 ore fa
Modificato: Matt J circa 6 ore fa
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))
pos_table = 9x4 table
Left Lower Width Height _______ ________ _______ _______ t = 1 0.065 0.7468 0.26976 0.13449 t = 2 0.37012 0.7468 0.26976 0.13449 t = 3 0.67524 0.7468 0.26976 0.13449 t = 4 0.065 0.4177 0.26976 0.13449 t = 5 0.37012 0.4177 0.26976 0.13449 t = 6 0.67524 0.4177 0.26976 0.13449 t = 7 0.065 0.088609 0.26976 0.13449 t = 8 0.37012 0.088609 0.26976 0.13449 t = 9 0.67524 0.088609 0.26976 0.13449

Star Strider
Star Strider circa un'ora fa
This may be a problem with the tiledlayout function.
Looking at the Position vectors of each of the axes, they all should have essentially the same widths, and they actually appear to. There is no obvious discrepancy between them. They are all very close, and should plot with the same appearances.
Someone from MathWorks may be able to resolve this.
My analysis —
figure(3);
clf
tiledlayout(3,3,"TileSpacing","compact","Padding","compact");
xlims = [-13,3];
ylims = [-3,3];
for ii = 1:9
to_plot = randn(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')
pos(ii,:) = ax.Position;
shading interp;
colormap("jet")
title(ax, "$t = " + num2str(ii) + "$",'interpreter','latex','fontsize',15)
hold off
axis equal
axis off
end
pos_table = array2table(pos, VariableNames={'Left','Lower','Width','Height'}, RowNames=compose('t = %d',1:9))
pos_table = 9x4 table
Left Lower Width Height _______ ________ _______ _______ t = 1 0.065 0.69199 0.27 0.27051 t = 2 0.3724 0.66243 0.26519 0.25573 t = 3 0.67524 0.66243 0.26976 0.25573 t = 4 0.065 0.36031 0.26742 0.24505 t = 5 0.3724 0.37739 0.26519 0.21089 t = 6 0.67524 0.37801 0.26976 0.20964 t = 7 0.065 0.051742 0.26519 0.20823 t = 8 0.3724 0.051742 0.26519 0.20823 t = 9 0.67524 0.051742 0.26976 0.20823
pos_stats = array2table([mean(pos(:,[3 4])); median(pos(:,[3 4])); std(pos(:,[3 4])); min(pos(:,[3 4])); max(pos(:,[3 4]))], VariableNames={'Width','Height'}, RowNames={'Mean','Median','StD','Min','Max'})
pos_stats = 5x2 table
Width Height _________ ________ Mean 0.2675 0.23025 Median 0.26742 0.21089 StD 0.0023178 0.025962 Min 0.26519 0.20823 Max 0.27 0.27051
.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by