Equally spaced figures in tiledlayout environment

2 views (last 30 days)
Hello everyone
I have generated the following image through the tiledlayout environment:
which I have generated through the following code:
u1=figure('visible','off','units','pixels','position',[0 0 1920 1080]);
tiledlayout("horizontal");
nexttile;
uimagesc(x,y,modulus');
Unrecognized function or variable 'x'.
axis xy;
hold off;
colormap;
box on;
clr1=colorbar;
set(clr1,'TickLabelInterpreter','latex');
xlabel('$x$-{\it th} spatial direction, $x$','FontSize',18,'interpreter','latex');
ylabel('$y$-{\it th} spatial direction, $y$','FontSize',18,'interpreter','latex');
ylabel(clr1,'Modulus, $\mathbf{H}$','Interpreter','Latex','FontSize',19);
clim([0 max(max(abs(modulus)))]);
xlim([0 50]);
xticks([0:10:50]);
ylim([0 50]);
yticks([0:10:50]);
pbaspect([1 1 1]);
set(gca,'TickLabelInterpreter','latex','FontSize',18);
nexttile;
image(angular_distribution);
hold off;
axis xy;
box on;
xlabel('$x$-{\it th} spatial direction, $x$','FontSize',18,'interpreter','latex');
ylabel('$y$-{\it th} spatial direction, $y$','FontSize',18,'interpreter','latex');
xlim([0 1000]);
xticks([0:200:1000]);
xticklabels({'0','10','20','30','40','50'});
ylim([0 1000]);
yticks([0:200:1000]);
yticklabels({'0','10','20','30','40','50'});
pbaspect([1 1 1]);
set(gca,'TickLabelInterpreter','latex','FontSize',18);
t1=title(['First case'],'FontSize',25,'interpreter','latex');
titleHandle=get(gca,'Title');
position_title=get(titleHandle,'position');
position1_title=[position_title(1) position_title(2)+420 position_title(3)];
set(titleHandle,'position',position1_title);
ax=nexttile;
image(angular_reference,'xdata',phi_range,'ydata',theta_range)
hold off;
box on;
axis xy;
xlabel('Azimuthal angle, $\phi \, \, \left( \pi \, \mathrm{rad} \right)$','FontSize',18,'interpreter','latex');
ylabel('Polar angle, $\theta \, \, \left( \pi \, \mathrm{rad} \right)$','FontSize',18,'interpreter','latex');
xlim([-pi pi]);
xticks([-pi:pi/2:pi]);
set(gca,'XTickLabel',{'-1','0.5','0','0.5','1'});
ylim([-pi/2 pi/2]);
yticks([-pi/2:pi/4:pi/2]);
set(gca,'YTickLabel',{'-0.5','0.25','0','0.25','0.5'});
xtickangle(ax,0);
ytickangle(ax,0);
pbaspect([1 1 1]);
set(gca,'TickLabelInterpreter','latex','FontSize',18);
set(gcf,'color','white');
set(gca,'Units','normalized')
set(u1,'Units','Inches');
posu1=get(u1,'Position');
set(u1,'PaperPositionMode','Auto','PaperUnits','Inches','PaperSize',[posu1(3),posu1(4)]);
As it can be seen, the empty space between the right end of the colorbar of the first figure and the beginning of the second figure, and the spacing between the right end of the second and left of the third figure are not equal. It seems that there is a kind of invisible colorbar accompanying the second figure. How could I make the figures truly equally spaced?
  1 Comment
Matt J
Matt J on 8 Dec 2023
Edited: Matt J on 8 Dec 2023
As seen above, your code does not run.
Unrecognized function or variable 'x'.

Sign in to comment.

Accepted Answer

Adam Danz
Adam Danz on 8 Dec 2023
Edited: Adam Danz on 8 Dec 2023
How could I make the figures truly equally spaced?
Using tiledlayout, the axes are equally spaced but the colorbar, axis labels, and other decorations fill some of the inter-axes space. There is currently no way to adjust the position properties of the axes in a tiled layout.
Here's a reduced version of the problem. Notice that I assigned the title to the TiledChartLayout object to achieve the global title in your question but without needing to position the title.
figure('Position',[100 100 700 150])
tcl = tiledlayout("horizontal");
nexttile()
imagesc(rand(500))
colorbar
nexttile()
imagesc(rand(500))
nexttile()
imagesc(rand(500))
title(tcl,'Global title')
Unlike tiledlayout, subplot adjusts the spacing while including the colorbar space. However, you lose several convenient features of tiledlayout. Also notice that the space consumed by the colorbar is taken away from the axis.
figure('Position',[100 100 700 150])
subplot(1,3,1)
imagesc(rand(500))
colorbar
subplot(1,3,2)
imagesc(rand(500))
subplot(1,3,3)
imagesc(rand(500))
One workaround using tiledlayout is to put the colorbar on the top or bottom of the axes
figure('Position',[100 100 700 250])
tcl = tiledlayout("horizontal");
nexttile()
imagesc(rand(500))
colorbar('Location','SouthOutside','Orientation','Horizontal')
nexttile()
imagesc(rand(500))
nexttile()
imagesc(rand(500))
title(tcl,'Global title')
Or on the left.
figure('Position',[100 100 700 200])
tcl = tiledlayout("horizontal");
nexttile()
imagesc(rand(500))
colorbar('Location','WestOutside')
nexttile()
imagesc(rand(500))
nexttile()
imagesc(rand(500))
title(tcl,'Global title')

More Answers (0)

Categories

Find more on Data Distribution Plots 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!