How do I change the type of colorbar for each tiled figure?

조회 수: 11 (최근 30일)
Jric
Jric 2023년 10월 20일
댓글: Akira Agata 2023년 10월 23일
Hi,
I have a figure with 4 tiles and manually edited the colorbar and made a new colorbar scheme in the matlab figure, but it only applies to my last tile. How do I get all of them to have the same colorbar scheme?
This is my code:
figure;
tiledlayout(1,4,'TileSpacing','Compact');
%Tile 1
nexttile
imagesc(TTest_DIF)
xlabel('{\it a}', 'FontWeight', 'bold', 'FontName', 'TimesNewRoman', 'FontSize', 12);
ylabel('{\it β}', 'FontWeight', 'bold', 'FontName', 'TimesNewRoman', 'FontSize', 12)
xticklabels({0 "" 0.2 "" 0.4 "" 0.6 "" 0.8 "" 1})
set(gca, 'xtick', 1:11, 'XTickLabel', xticklabels)
yticklabels({1 "" "" "" "" 0})
set(gca, 'ytick', 1:6, 'YTickLabels', yticklabels)
title('{\Delta_t - \Delta_c}', 'FontWeight', 'bold', 'FontName', 'TimesNewRoman', 'FontSize', 14)
clim([-72 11]) % EDIT THESE LIMITS
%Tile 2
nexttile
imagesc(BSITTest_DIF)
%xlabel('{\it a}', 'FontWeight', 'bold', 'FontName', 'TimesNewRoman', 'FontSize', 10);
ylabel('{\it β}', 'FontWeight', 'bold', 'FontName', 'TimesNewRoman', 'FontSize', 12)
xlabel('{\it a}', 'FontWeight', 'bold', 'FontName', 'TimesNewRoman', 'FontSize', 12);
xticklabels({0 "" 0.2 "" 0.4 "" 0.6 "" 0.8 "" 1})
set(gca, 'xtick', 1:11, 'XTickLabel', xticklabels)
yticklabels({1 "" "" "" "" 0})
set(gca, 'ytick', 1:6, 'YTickLabels', yticklabels)
title('{\Delta_B_I_T - \Delta_c}', 'FontWeight', 'bold', 'FontName', 'TimesNewRoman', 'FontSize', 14)
clim([-72 11]) % EDIT THESE LIMITS
%tile 3
nexttile
imagesc(Slope_DIF)
%had to change to DeltaSlopeE' in workspace as it was 11x6 not 6x11.
%xlabel('{\it a}', 'FontWeight', 'bold', 'FontName', 'TimesNewRoman', 'FontSize', 10);
ylabel('{\it β}', 'FontWeight', 'bold', 'FontName', 'TimesNewRoman', 'FontSize', 12)
xlabel('{\it a}', 'FontWeight', 'bold', 'FontName', 'TimesNewRoman', 'FontSize', 12);
xticklabels({0 "" 0.2 "" 0.4 "" 0.6 "" 0.8 "" 1})
set(gca, 'xtick', 1:11, 'XTickLabel', xticklabels)
yticklabels({1 "" "" "" "" 0})
set(gca, 'ytick', 1:6, 'YTickLabels', yticklabels)
title('{\Delta_s - \Delta_c}', 'FontWeight', 'bold', 'FontName', 'TimesNewRoman', 'FontSize', 14)
clim([-72 11])
%tile 4
nexttile
imagesc(Slope_BIT_DIF)
%had to change to DeltaSlopeE' in workspace as it was 11x6 not 6x11.
%xlabel('{\it a}', 'FontWeight', 'bold', 'FontName', 'TimesNewRoman', 'FontSize', 10);
ylabel('{\it β}', 'FontWeight', 'bold', 'FontName', 'TimesNewRoman', 'FontSize', 12)
xlabel('{\it a}', 'FontWeight', 'bold', 'FontName', 'TimesNewRoman', 'FontSize', 12);
xticklabels({0 "" 0.2 "" 0.4 "" 0.6 "" 0.8 "" 1})
set(gca, 'xtick', 1:11, 'XTickLabel', xticklabels)
yticklabels({1 "" "" "" "" 0})
set(gca, 'ytick', 1:6, 'YTickLabels', yticklabels)
title('{\Delta_s - \Delta_B_I_T}', 'FontWeight', 'bold', 'FontName', 'TimesNewRoman', 'FontSize', 14)
clim([-72 11])
% colorbar
clim([-72 11]) % EDIT THESE LIMITS
cb = colorbar;
cb.Layout.Tile = 'south'
cb.Position = cb.Position + 1e-10;
set(gcf,'PaperSize',[8.5 11])
This is the image:
Thank you in advance :)

답변 (1개)

Akira Agata
Akira Agata 2023년 10월 20일
You can set colormap for each axes object, like:
% sample data
z = peaks(20);
% display the data with different colormap
tiledlayout(1, 4);
ax1 = nexttile;
imagesc(z)
colormap(ax1, "parula")
colorbar("southoutside")
ax2 = nexttile;
imagesc(z)
colormap(ax2, "hsv")
colorbar("southoutside")
ax3 = nexttile;
imagesc(z)
colormap(ax3, "abyss")
colorbar("southoutside")
ax4 = nexttile;
imagesc(z)
colormap(ax4, "autumn")
colorbar("southoutside")
  댓글 수: 2
Jric
Jric 2023년 10월 23일
Thank you. Any idea how to do this with custom made colormaps too?
Akira Agata
Akira Agata 2023년 10월 23일
@Jric-san
Yes, you can use your custom colormap in the same way, like:
% sample data
z = peaks(20);
% custom colormap
cMap = [1 0 0; 0 1 0; 0 0 1];
% display the data with different colormap
tiledlayout(1, 4);
ax1 = nexttile;
imagesc(z)
colormap(ax1, "parula")
colorbar("southoutside")
ax2 = nexttile;
imagesc(z)
colormap(ax2, "hsv")
colorbar("southoutside")
ax3 = nexttile;
imagesc(z)
colormap(ax3, "abyss")
colorbar("southoutside")
ax4 = nexttile;
imagesc(z)
colormap(ax4, cMap) % <- custom colormap
colorbar("southoutside")

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Signal Analysis에 대해 자세히 알아보기

제품


릴리스

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by