Colorbar String Spacing Issue
7 次查看(过去 30 天)
显示 更早的评论
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
2021-5-17
编辑:Adam Danz
2021-5-17
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 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Colorbar 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!