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

조회 수: 12 (최근 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
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.
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 CenterFile Exchange에서 Colorbar에 대해 자세히 알아보기

태그

아직 태그를 입력하지 않았습니다.

제품


릴리스

R2006a

Community Treasure Hunt

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

Start Hunting!

Translated by