Shared Tiledlayout colorbar for R2020a

3 次查看(过去 30 天)
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 ?

回答(1 个)

Nivedita
Nivedita 2023-9-7
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);
surf(Z1);
ax(2) = subplot(2,2,2);
surf(Z2);
ax(3) = subplot(2,2,3);
surf(Z3);
ax(4) = subplot(2,2,4);
surf(Z4);
set(ax, 'Colormap', jet, 'Clim', [-50, 150]);
cbh=colorbar(ax(end));
% 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!
Regards,
Nivedita.

类别

Help CenterFile Exchange 中查找有关 Purple 的更多信息

产品


版本

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by