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

Adam Danz
Adam Danz 2021년 5월 17일
What release of Matlab are you using? I cannot replicate the problem in r2021a.
Sebastian
Sebastian 2021년 5월 17일
편집: Sebastian 2021년 5월 17일
Okay, we are using Matlab 2020b.
Adam Danz
Adam Danz 2021년 5월 17일
편집: Adam Danz 2021년 5월 20일
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.

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

 채택된 답변

Adam Danz
Adam Danz 2021년 5월 17일
편집: Adam Danz 2021년 5월 17일

0 개 추천

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')

추가 답변 (0개)

카테고리

질문:

2021년 5월 17일

편집:

2021년 5월 20일

Community Treasure Hunt

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

Start Hunting!

Translated by