Change width of 2 colorbars in tiledlayout
I try to change the width of the colorbars in both r
If I only change it for one of them, it works.
img_sos = rand(64);
img_oar_pixel = rand(64);
img_oar_block = rand(64);
snr_sos = rand(64)*250;
snr_oar_pixel = rand(64)*250;
snr_oar_block = rand(64)*250;
snr_max = ceil(max([snr_sos(:); snr_oar_pixel(:); snr_oar_block(:)]));
snr_max_50 = ceil(snr_max / 50) * 50;
tile_size_cm = 4; % desired size of images
n_cols = 3;
n_rows = 2;
padding_cm = 0.6;
colorbar_width_cm = 1;
% size of figure
fig_width_cm = n_cols * tile_size_cm + (n_cols+1)*padding_cm + colorbar_width_cm;
fig_height_cm = n_rows * tile_size_cm + (n_rows+1)*padding_cm;
f = figure(‘Units’, ‘centimeters’, ‘Position’, [5 5 fig_width_cm fig_height_cm]);
tl = tiledlayout(n_rows, n_cols, ‘TileSpacing’, ‘compact’, ‘Padding’, ‘compact’);
clim1 = [0 1];
cmap1 = jet;
ax1 = [];
ax1(1) = nexttile(1);
imagesc(img_sos, clim1);
axis image off;
title(‘Sum-of-Squares’, ‘FontSize’, 10, ‘Interpreter’, ‘latex’, …
‘FontName’, ‘Latin Modern Roman’);
ax1(2) = nexttile(2);
imagesc(img_oar_pixel, clim1);
axis image off;
title({‘Adaptive Kombination’, ‘(Pixelweise)’}, ‘FontSize’, 10, ‘Interpreter’, ‘latex’, …
‘FontName’, ‘Latin Modern Roman’);
ax1(3) = nexttile(3);
imagesc(img_oar_block, clim1);
axis image off;
title({‘Adaptive Kombination’, ‘(Blockweise)’}, ‘FontSize’, 10, ‘Interpreter’, ‘latex’, …
‘FontName’, ‘Latin Modern Roman’);
set(ax1, ‘Colormap’, cmap1);
cb1 = colorbar(ax1(end), ‘eastoutside’);
cb1.Label.String = ‘Normierte Signalintensit"at’;
cb1.Label.Interpreter = ‘latex’;
cb1.Label.FontSize = 10;
cb1.Ticks = 0:0.2:1;
% THIS IS WHAT I WANT TO DO FOR THE SECOND ONE AS WELL
fixed_cb_width_cm = 0.3;
cb1_pos = cb1.Position;
cb1_pos(3) = fixed_cb_width_cm / fig_width_cm;
cb1.Position = cb1_pos;
clim2 = [0 snr_max_50];
cmap2 = hot;
ax2 = [];
ax2(1) = nexttile(4);
imagesc(snr_sos, clim2);
axis image off;
ax2(2) = nexttile(5);
imagesc(snr_oar_pixel, clim2);
axis image off;
ax2(3) = nexttile(6);
imagesc(snr_oar_block, clim2);
axis image off;
set(ax2, ‘Colormap’, cmap2);
cb2 = colorbar(ax2(end), ‘eastoutside’);
cb2.Label.String = ‘SNR’;
cb2.Label.Interpreter = ‘latex’;
cb2.Label.FontSize = 10;
cb2.Ticks = 0:50:snr_max_50;
But as soon as I add this part for the second one:
cb2_pos = cb2.Position;
cb2_pos(3) = fixed_cb_width_cm / fig_width_cm;
cb2.Position = cb2_pos;
Both colorbars appear inside the last image ..I try to change the width of the colorbars in both r
If I only change it for one of them, it works.
img_sos = rand(64);
img_oar_pixel = rand(64);
img_oar_block = rand(64);
snr_sos = rand(64)*250;
snr_oar_pixel = rand(64)*250;
snr_oar_block = rand(64)*250;
snr_max = ceil(max([snr_sos(:); snr_oar_pixel(:); snr_oar_block(:)]));
snr_max_50 = ceil(snr_max / 50) * 50;
tile_size_cm = 4; % desired size of images
n_cols = 3;
n_rows = 2;
padding_cm = 0.6;
colorbar_width_cm = 1;
% size of figure
fig_width_cm = n_cols * tile_size_cm + (n_cols+1)*padding_cm + colorbar_width_cm;
fig_height_cm = n_rows * tile_size_cm + (n_rows+1)*padding_cm;
f = figure(‘Units’, ‘centimeters’, ‘Position’, [5 5 fig_width_cm fig_height_cm]);
tl = tiledlayout(n_rows, n_cols, ‘TileSpacing’, ‘compact’, ‘Padding’, ‘compact’);
clim1 = [0 1];
cmap1 = jet;
ax1 = [];
ax1(1) = nexttile(1);
imagesc(img_sos, clim1);
axis image off;
title(‘Sum-of-Squares’, ‘FontSize’, 10, ‘Interpreter’, ‘latex’, …
‘FontName’, ‘Latin Modern Roman’);
ax1(2) = nexttile(2);
imagesc(img_oar_pixel, clim1);
axis image off;
title({‘Adaptive Kombination’, ‘(Pixelweise)’}, ‘FontSize’, 10, ‘Interpreter’, ‘latex’, …
‘FontName’, ‘Latin Modern Roman’);
ax1(3) = nexttile(3);
imagesc(img_oar_block, clim1);
axis image off;
title({‘Adaptive Kombination’, ‘(Blockweise)’}, ‘FontSize’, 10, ‘Interpreter’, ‘latex’, …
‘FontName’, ‘Latin Modern Roman’);
set(ax1, ‘Colormap’, cmap1);
cb1 = colorbar(ax1(end), ‘eastoutside’);
cb1.Label.String = ‘Normierte Signalintensit"at’;
cb1.Label.Interpreter = ‘latex’;
cb1.Label.FontSize = 10;
cb1.Ticks = 0:0.2:1;
% THIS IS WHAT I WANT TO DO FOR THE SECOND ONE AS WELL
fixed_cb_width_cm = 0.3;
cb1_pos = cb1.Position;
cb1_pos(3) = fixed_cb_width_cm / fig_width_cm;
cb1.Position = cb1_pos;
clim2 = [0 snr_max_50];
cmap2 = hot;
ax2 = [];
ax2(1) = nexttile(4);
imagesc(snr_sos, clim2);
axis image off;
ax2(2) = nexttile(5);
imagesc(snr_oar_pixel, clim2);
axis image off;
ax2(3) = nexttile(6);
imagesc(snr_oar_block, clim2);
axis image off;
set(ax2, ‘Colormap’, cmap2);
cb2 = colorbar(ax2(end), ‘eastoutside’);
cb2.Label.String = ‘SNR’;
cb2.Label.Interpreter = ‘latex’;
cb2.Label.FontSize = 10;
cb2.Ticks = 0:50:snr_max_50;
But as soon as I add this part for the second one:
cb2_pos = cb2.Position;
cb2_pos(3) = fixed_cb_width_cm / fig_width_cm;
cb2.Position = cb2_pos;
Both colorbars appear inside the last image .. I try to change the width of the colorbars in both r
If I only change it for one of them, it works.
img_sos = rand(64);
img_oar_pixel = rand(64);
img_oar_block = rand(64);
snr_sos = rand(64)*250;
snr_oar_pixel = rand(64)*250;
snr_oar_block = rand(64)*250;
snr_max = ceil(max([snr_sos(:); snr_oar_pixel(:); snr_oar_block(:)]));
snr_max_50 = ceil(snr_max / 50) * 50;
tile_size_cm = 4; % desired size of images
n_cols = 3;
n_rows = 2;
padding_cm = 0.6;
colorbar_width_cm = 1;
% size of figure
fig_width_cm = n_cols * tile_size_cm + (n_cols+1)*padding_cm + colorbar_width_cm;
fig_height_cm = n_rows * tile_size_cm + (n_rows+1)*padding_cm;
f = figure(‘Units’, ‘centimeters’, ‘Position’, [5 5 fig_width_cm fig_height_cm]);
tl = tiledlayout(n_rows, n_cols, ‘TileSpacing’, ‘compact’, ‘Padding’, ‘compact’);
clim1 = [0 1];
cmap1 = jet;
ax1 = [];
ax1(1) = nexttile(1);
imagesc(img_sos, clim1);
axis image off;
title(‘Sum-of-Squares’, ‘FontSize’, 10, ‘Interpreter’, ‘latex’, …
‘FontName’, ‘Latin Modern Roman’);
ax1(2) = nexttile(2);
imagesc(img_oar_pixel, clim1);
axis image off;
title({‘Adaptive Kombination’, ‘(Pixelweise)’}, ‘FontSize’, 10, ‘Interpreter’, ‘latex’, …
‘FontName’, ‘Latin Modern Roman’);
ax1(3) = nexttile(3);
imagesc(img_oar_block, clim1);
axis image off;
title({‘Adaptive Kombination’, ‘(Blockweise)’}, ‘FontSize’, 10, ‘Interpreter’, ‘latex’, …
‘FontName’, ‘Latin Modern Roman’);
set(ax1, ‘Colormap’, cmap1);
cb1 = colorbar(ax1(end), ‘eastoutside’);
cb1.Label.String = ‘Normierte Signalintensit"at’;
cb1.Label.Interpreter = ‘latex’;
cb1.Label.FontSize = 10;
cb1.Ticks = 0:0.2:1;
% THIS IS WHAT I WANT TO DO FOR THE SECOND ONE AS WELL
fixed_cb_width_cm = 0.3;
cb1_pos = cb1.Position;
cb1_pos(3) = fixed_cb_width_cm / fig_width_cm;
cb1.Position = cb1_pos;
clim2 = [0 snr_max_50];
cmap2 = hot;
ax2 = [];
ax2(1) = nexttile(4);
imagesc(snr_sos, clim2);
axis image off;
ax2(2) = nexttile(5);
imagesc(snr_oar_pixel, clim2);
axis image off;
ax2(3) = nexttile(6);
imagesc(snr_oar_block, clim2);
axis image off;
set(ax2, ‘Colormap’, cmap2);
cb2 = colorbar(ax2(end), ‘eastoutside’);
cb2.Label.String = ‘SNR’;
cb2.Label.Interpreter = ‘latex’;
cb2.Label.FontSize = 10;
cb2.Ticks = 0:50:snr_max_50;
But as soon as I add this part for the second one:
cb2_pos = cb2.Position;
cb2_pos(3) = fixed_cb_width_cm / fig_width_cm;
cb2.Position = cb2_pos;
Both colorbars appear inside the last image .. figure, subplot, color, axes MATLAB Answers — New Questions