Borrar filtros
Borrar filtros

Colorbar String Spacing Issue

7 visualizaciones (últimos 30 días)
Sebastian
Sebastian el 17 de Mayo de 2021
Editada: Adam Danz el 20 de Mayo de 2021
I have some issues using 'colorbar'. To my problem: I would like to to plot a certain number (let's say 4) of different contourf-diagrams in a created 'tiledlayout'. The content is not important for my issue which is why I simply chose 'peaks' in the following. To keep the whole thing concise, a common x- and y-label should be used.
fig= figure('color', 'w');
tile= tiledlayout(2,2,'TileSpacing','normal','Padding', 'normal');
for a=1:4
nexttile(a);
contourf(peaks);
set(gca, 'FontSize', 14);
title(['Plot No. ', num2str(a)],'FontName','Arial Narrow','FontSize',14);
end
xlabel(tile, 'X-Label [unit]');
ylabel(tile, 'Y-Label [unit]');
For all plots I would like to place a common central colorbar below. However, this colorbar should still be provided with a label. I first tried to insert a string like in the examples:
cb= colorbar('FontName','Arial Narrow','FontSize',14);
% attempt #1:
cb.Label.String = 'CBar Label';
cb.AxisLocation = 'in';
cb.Layout.Tile= 'south'; % 'in' and 'out' doesn't make a difference in the south location
The problem is that the string of the colorbar is colliding with the xlabel. First I tought it just has to be done in diferent order (without success) :
% cb.Layout.Tile= 'south';
% cb.Label.String = 'CBar Label';
% cb.AxisLocation = 'in';
When I completely leave out the xlabel, the string will be truncated and is only partially displayed. Another idea was to use the title-function:
% attempt #2:
title(cb,'CBar Label', 'FontSize',14); % alternatively tried: xlabel(cb,...) and ylabel(cb,...)
cb.Layout.Tile= 'south';
Here the x-label is placed under the color bar, which is very unfavorable and misleading. I know that 'tiledlayout' is a relatively new and still under development but this problem occurs when using single plots as well. It seems to me that there is a problem with the location, as if the label is not correctly linked to the colorbar. So maybe the reason is wrong figure properties. I hope somebody can help. Thanks in advance!
  3 comentarios
Sebastian
Sebastian el 17 de Mayo de 2021
Editada: Sebastian el 17 de Mayo de 2021
Okay, we are using Matlab 2020b.
Adam Danz
Adam Danz el 17 de Mayo de 2021
Editada: Adam Danz el 20 de Mayo de 2021
Perhaps you could try the ylabel() method shown in my answer. It might position the label differently than assing the string directly to the Label property.

Iniciar sesión para comentar.

Respuesta aceptada

Adam Danz
Adam Danz el 17 de Mayo de 2021
Editada: Adam Danz el 17 de Mayo de 2021
The problem with overlapping labels must have been solved in Matlab R2021a.
I agree that the xlabel should be above the colorbar. You could submit a feature request: Contact Us - MATLAB & Simulink
fig= figure('color', 'w');
tile= tiledlayout(2,2,'TileSpacing','normal','Padding', 'normal');
for a=1:4
nexttile(a);
contourf(peaks);
set(gca, 'FontSize', 14);
title(['Plot No. ', num2str(a)],'FontName','Arial Narrow','FontSize',14);
end
xlabel(tile, 'X-Label [unit]');
ylabel(tile, 'Y-Label [unit]');
cb= colorbar('FontName','Arial Narrow','FontSize',14);
cb.Layout.Tile= 'south';
ylabel(cb,'CBar Label');
title(cb, 'CBar title')

Más respuestas (0)

Community Treasure Hunt

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

Start Hunting!

Translated by