Clear Filters
Clear Filters

Shared Tiledlayout colorbar for R2020a

3 views (last 30 days)
So there is a fast method for versions R2020b and after to place a shared colorbar. But I have 2020a. How can a shared colorbar be placed without the colorbar.Layout property ?

Answers (1)

Nivedita on 7 Sep 2023
Hi Alessandro,
I understand that you are looking for an alternative way to create a shared Colorbar in MATLAB R2020a which does not support the “colorbar.Layout” property.
You can work around this issue by utilising the “colorbar.Position” property. Here is an example:
[X,Y] = meshgrid(-5:.5:5);
Z1 = X.^2 + Y.^2;
Z2 = Z1 + 50;
Z3 = Z1 + 100;
Z4 = Z1 - 50;
% Create the main figure and axes for your plots
fig = figure();
% Generate the plots and store their handles
ax(1) = subplot(2,2,1);
ax(2) = subplot(2,2,2);
ax(3) = subplot(2,2,3);
ax(4) = subplot(2,2,4);
set(ax, 'Colormap', jet, 'Clim', [-50, 150]);
% Reposition colorbar to the figure's left edge by manually using the Position property
cbh.Position(1) = 0.93;
cbh.Position(2) = 0.05;
cbh.Position(3) = 0.02;
cbh.Position(4) = 0.9;
In the above code, I have generated a sample data and used the “subplot” function to achieve the tiled view of the plots. I have stored their handles in the “ax” variable to use it later to assign a shared colormap for the generated plots using the “set” function.
Then, the Colorbar handles has been stored in the “cbh” variable. To achieve the shared Colorbar, I have manually used the “Position” property to reposition the Colorbar to the left edge of the figure and changed its dimensions.
Here is what the output looks:
For more information about the “colorbar.Position” property, you can refer to the following documentation link: Colorbar.Position
I hope this helps!


Find more on Colormaps 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!