How to put a colorbar between the columns in tiledlayout?
18 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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!
0 Kommentare
Akzeptierte Antwort
Voss
am 23 Okt. 2024
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 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Data Distribution Plots finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
