How to put a colorbar between the columns in tiledlayout?

7 ビュー (過去 30 日間)
Konstantin
Konstantin 2024 年 10 月 23 日
コメント済み: Voss 2024 年 10 月 24 日
Hello,
I cannot figure out how to put a colorbar between the columns in tiledlayout. I searched for possible answers but unfortunately could not solve my problem. Please give me a link if there is an answer already.
Here is the chunk of code I use:
figSlices = figure('Position', [0, 0, 2 * 300, 3 * 250], 'Units', 'pixels', ...
'Name', ['nFreqs ' num2str(length(Geometry.freqsVec))]);
tlo = tiledlayout(3, 2, "TileSpacing", "compact", "Padding", "compact", ...
"TileIndexing", "columnmajor");
for i = 1:3
hAbs(i) = nexttile(tlo);
imagesc(0.5*ones(50,50), [0 1]);
end
set(hAbs, 'Colormap', hot, 'CLim', [0 1]);
cbAbs = colorbar(hAbs(end));
cbAbs.Layout.Tile = 'west';
for i = 1:3
hSca(i) = nexttile(tlo);
imagesc(1.2*ones(50, 50), [1 2]);
end
set(hSca, 'Colormap', hot, 'CLim', [1 2]);
cbSca = colorbar(hSca(end));
cbSca.Layout.Tile = 'east';
And I get something like looking below.
I want, however, that the top colorbar is near the left column in the image and stretched over all the 3 tiles in the first column. While the bottom colorbar must go on the right of the second column and also stretched across all rows.
Changing
cbAbs.Layout.Tile = 'east'; to cbAbs.Layout.Tile = 'west';
I get the image like this:
This is close to what I want, but the left colormap must be in between the figure, on the right side of the left column. How to do it?
Thanks!

採用された回答

Voss
Voss 2024 年 10 月 23 日
One solution is to use nested tiledlayouts; in this case a 1x2 tiledlayout containing two 3x1 tiledlayouts.
figSlices = figure('Units', 'pixels', 'Position', [0, 0, 2 * 300, 3 * 250]);
outer_tl = tiledlayout(1, 2, "TileSpacing", "compact", "Padding", "compact");
N = 3;
inner_tl = tiledlayout(outer_tl,N,1,"TileSpacing", "compact", "Padding", "compact");
inner_tl.Layout.Tile = 1;
ax = gobjects(N,1);
for ii = 1:N
ax(ii) = nexttile(inner_tl);
imagesc(ax(ii), 0.5*ones(50,50), [0 1]);
end
set(ax, 'Colormap', hot, 'CLim', [0 1]);
cb = colorbar(ax(end));
cb.Layout.Tile = 'east';
N = 3;
inner_tl = tiledlayout(outer_tl,N,1,"TileSpacing", "compact", "Padding", "compact");
inner_tl.Layout.Tile = 2;
ax = gobjects(N,1);
for ii = 1:N
ax(ii) = nexttile(inner_tl);
imagesc(ax(ii), 1.2*ones(50,50), [1 2]);
end
set(ax, 'Colormap', hot, 'CLim', [1 2]);
cb = colorbar(ax(end));
cb.Layout.Tile = 'east';
  2 件のコメント
Konstantin
Konstantin 2024 年 10 月 24 日
Thank you! I did not consider before the nested layouts and from now on will use them when needed.
Voss
Voss 2024 年 10 月 24 日
You're welcome!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeOrange についてさらに検索

製品


リリース

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by