# How can I reposition the colorbar to not overlap my x-axis label?

11 ビュー (過去 30 日間)
MathWorks Support Team 2009 年 6 月 27 日

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)

サインインしてコメントする。

### その他の回答 (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')

サインインしてコメントする。

### カテゴリ

Help Center および File ExchangeColorbar についてさらに検索

タグが未入力です。

R2006a

### Community Treasure Hunt

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

Start Hunting!

Translated by