필터 지우기
필터 지우기

Shared Tiledlayout colorbar for R2020a

조회 수: 3 (최근 30일)
Alessandro Maria Laspina
Alessandro Maria Laspina 2022년 7월 22일
답변: Nivedita 2023년 9월 7일
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에서 Colormaps에 대해 자세히 알아보기

제품


릴리스

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by