How can I reposition the colorbar to not overlap my x-axis label?
8 次查看(过去 30 天)
显示 更早的评论
When I create a plot with a horizontal colorbar my x-axis label is covered by the colorbar itself so that it is no longer visible. How can I reposition my colorbar so that the label is uncovered.
plot(1:10);
xlabel('\Omega_m');
ylabel('H_0');
hbar = colorbar('horiz');
xlabel(hbar,'\Omega_c h^2');
采纳的回答
MathWorks Support Team
2009-6-27
To ensure that overlap of the x-axis label and the colorbar does not occur, you can modify the position of the axes in the figure and the position of the colorbar. For example:
%Create Plot as before
plot(1:10);
xlabel('\Omega_m');
ylabel('H_0');
ax = gca;
hbar = colorbar('horiz');
xlabel(hbar,'\Omega_c h^2');
% Modify Colorbar to a manual setting
set(hbar,'location','manual','ActivePositionProperty','OuterPosition')
% Reset the outerposition of the colorbar to be normalized from figure
hbarPos = get(hbar,'OuterPosition');
set(hbar,'OuterPosition',[0 0 1 hbarPos(4)])
% What are the axes positions and margin info
axPos = get(ax,'Position');
axMargin = get(ax,'TightInset');
% Calculate and set new position of axes to accomodate colorbar and margins
newAxPos = [axPos(1),hbarPos(4)+axMargin(2),...
axPos(3), axPos(4)+axPos(2)-hbarPos(4)-axMargin(2)-axMargin(4)];
set(ax,'ActivePositionProperty','Position','Position',newAxPos)
0 个评论
更多回答(1 个)
Mr M.
2018-7-24
Error using matlab.graphics.illustration.ColorBar/set There is no activepositionproperty property on the ColorBar class.
set(hbar,'location','manual','activepositionproperty','outerposition')
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Axis Labels 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!