Clear Filters
Clear Filters

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

10 views (last 30 days)
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 :)

Answers (1)

Akira Agata
Akira Agata on 20 Oct 2023
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 Comments
Jric
Jric on 23 Oct 2023
Thank you. Any idea how to do this with custom made colormaps too?
Akira Agata
Akira Agata on 23 Oct 2023
@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")

Sign in to comment.

Products


Release

R2022b

Community Treasure Hunt

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

Start Hunting!