Add shared colorbar on some rows only
25 views (last 30 days)
Show older comments
Eka Sulistyawan
on 20 Aug 2023
Commented: Eka Sulistyawan
on 20 Aug 2023
Hi, I am using MATLAB R2021b (though, I got access to an earlier R2023~ version) and have to make the following layout using the tiledlayout,
Tile 1 to 8 were basically imagesc and Tile 9 to 12 were line plots. Is this possible?
Thanks in advance!
0 Comments
Accepted Answer
Dave B
on 20 Aug 2023
You can accomplish this kind of layout by nesting tiledlayouts, and leveraging the TileSpan property.
Below, I create a 3 x 1 top layout, which will hold two child layouts. The first one will contain all the images, and because it holds twice as many rows I made it have a TileSpan that's twice that of the second child layout. To share the colorbar, I just placed it in the 'east' tile.
Note that even though the colorbar is 'shared' this only affects the way it's positioned, it is still linked to the color limits of one axes (the 8th tile in the example below). Consider setting all of the CLim of the 8 axes to be the same so that the scale correctly describes the set of axes it's visually linked to.
t0=tiledlayout(3,1); % A 'container' layout that holds two other layouts
t1=tiledlayout(t0,2,4); % The layout holding the images, and the colorbar
t1.Layout.Tile=1;
t1.Layout.TileSpan=[2 1]; % A TileSpan prevents the two rows from being squished to match the lower layout's height
for i = 1:8
nexttile(t1)
imagesc(peaks)
end
c=colorbar;
c.Layout.Tile='east';
t2=tiledlayout(t0,1,4);
t2.Layout.Tile = 3;
for i = 1:4
nexttile(t2)
plot(magic(5))
end
More Answers (0)
See Also
Categories
Find more on Axes Appearance in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!