Borrar filtros
Borrar filtros

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

10 visualizaciones (últimos 30 días)
Jric
Jric el 20 de Oct. de 2023
Comentada: Akira Agata el 23 de Oct. de 2023
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 :)

Respuestas (1)

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

Iniciar sesión para comentar.

Productos


Versión

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by