Global ylabel and colorbar in tiledlayout environment
4 views (last 30 days)
Show older comments
Dear all
I am creating a figure in tiledlayout environment through a code of the form:
% First layer
u1=figure('visible','off','units','pixels','position',[0 0 1920 1080]);
t=tiledlayout("vertical");
title(t,['Trilayer. First layer. LLG-Heun, $t=1.09$ ns. $T=0$ K, $\mathbf{H}=\left( 0.5 \, \, \mathrm{T} \right) \mathbf{\hat{z}}$';'';''],'FontSize',19,'interpreter','latex');
nexttile;
uimagesc(space_x,space_y,lx_1);
axis xy;
clim([-1 1]);
colormap(bluewhitered(256));
box on;
xlim([0 200]);
xticks([0:50:200]);
ylim([0 50]);
yticks([0:10:50]);
pbaspect([max(space_x)/max(space_y) 1 1]);
xtickangle(0);
set(gca,'TickLabelInterpreter','latex','FontSize',18);
t1=title(['$l^{\mathrm{intra}}_x$'],'FontSize',20,'interpreter','latex');
set(t1,'interpreter','latex','FontSize',20);
set(gca,'XTickLabel',[]);
yticks([0:50/4:50]);
nexttile;
uimagesc(space_x,space_y,ly_1);
clim([-1 1]);
colormap(bluewhitered(256));
axis xy;
box on;
clr2=colorbar;
set(clr2,'TickLabelInterpreter','latex');
ylabel('$y$-{\it th} spatial direction, $y \, \, \left( \mathrm{nm} \right)$','FontSize',18,'interpreter','latex');
ylabel(clr2,'$i$-{\it th} intralayer Ne\''el vector component, $l^{\mathrm{intra}}_i$','Interpreter','Latex','FontSize',19);
xlim([0 200]);
xticks([0:50:200]);
ylim([0 50]);
yticks([0:10:50]);
pbaspect([max(space_x)/max(space_y) 1 1]);
xtickangle(0);
set(gca,'TickLabelInterpreter','latex','FontSize',18);
t2=title(['$l^{\mathrm{intra}}_y$'],'FontSize',20,'interpreter','latex');
set(t2,'interpreter','latex','FontSize',20);
set(gca,'XTickLabel',[]);
yticks([0:50/4:50]);
nexttile;
uimagesc(space_x,space_y,lz_1);
box on;
axis xy;
clim([-1 1]);
colormap(bluewhitered(256));
xlabel('$x$-{\it th} spatial direction, $x \, \, \left( \mathrm{nm} \right)$','FontSize',18,'interpreter','latex');
xlim([0 200]);
xticks([0:50:200]);
ylim([0 50]);
yticks([0:10:50]);
pbaspect([max(space_x)/max(space_y) 1 1]);
xtickangle(0);
set(gca,'TickLabelInterpreter','latex','FontSize',18);
t3=title(['$l^{\mathrm{intra}}_z$'],'FontSize',20,'interpreter','latex');
set(t3,'interpreter','latex','FontSize',20);
yticks([0:50/4:50]);
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)]);
which gives rise to:
I would like to have the ylabel "y-th spatial direction..." centered in the second plot, but covering the three y-axis (as it is now, but with a higher separation from the yticklabels (0 12.5...) to the left. Moreover, I want the same for the colorbar, that it is, to be the global one for the three plots, with higher horizontal separation to the right, and with a longer aspect (from the bottom of the bottom plot to the top of the top plot).
Any ideas?
1 Comment
dpb
on 3 Aug 2024
Edited: dpb
on 4 Aug 2024
Not easy without the data to try to reproduce/mung on yours, but MATLAB anticipated you on the <shared colorbar> there's a shared example down a few from the top-level examples link above.
You can adjust the 'Position' property of the y-label as you wish; simply subtract a small amount from the first element of the 4-vector; the values are [left, bottom, width, height] in axis units so the x-positions will be in magnitudes of x.
I'm not sure you can get to the yticklabel text object for the colorbar tick labels...
One additional customization I'd suggest would be to get rid of the proverbial-appendage ugly difference in y axis tick label formatting that comes from the default '%g' so the labels aren't aligned nor consistent in precision. Add
hAx=nexttile; % return a handle; using an array would let you at any particular one
....
hAx.YAxis.TickLabelFormat='%.1f';
...
For the shared axes labels, the venerable x- ylabel functions have also been overloaded to accept the handle of the tiled layout object to create them as shared, so you could replace
ylabel('$y$-{\it th} spatial direction, $y \, \, \left( \mathrm{nm} \right)$','FontSize',18,'interpreter','latex');
with
ylabel(t,'$y$-{\it th} spatial direction, $y \, \, \left( \mathrm{nm} \right)$','FontSize',18,'interpreter','latex');
similarly as you did for the title. (Personally, I would use "hT" or something similar for the handle to remind me it is a handle and not a regular variable, but that's just stylistic, not functional).
Answers (1)
Gautam
on 23 Aug 2024
Hello Richard,
I understand that you want the title to the left of your plot to have higher separation from the `y` ticks and you want to display a colorbar which is the same for all the three plots.
You can adjust the separation of the title by creating a handle to the title and changing the value of its “Position” property as :
labely_left = ylabel('$y$-{\it th} spatial direction, $y \, \, \left( \mathrm{nm} \right)$','FontSize',18,'interpreter','latex');
set(labely_left, "Position", [-2 21 1]);
To make the colorbar same for all the three tiles change the “Layout.Tile” property of the colorbar handle in your code.
clr2.Layout.Tile = 'east';
The image below shows a sample plot. I have made my own plots due to absence of the data but have kept the titles, their styles and the styles of the ticks the same
Hope this helps.
0 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!