How to make the label inside of the figure box

조회 수: 48 (최근 30일)
MathWorks Support Team
MathWorks Support Team 2018년 6월 4일
답변: MathWorks Support Team 2018년 6월 4일
Why does the xlabel command add the label outside of the figure box and changing the 'OuterPosition' and 'InnerPosition' properties does't work?
The following will reproduce the issue:
Starting with a figure containing an x-y plot, add a second set of axes using
ax1=gca;
ax1_pos = ax1.Position; % position of first axes
ax2 = axes('Position',ax1_pos,...
'XAxisLocation','top',...
'Color','none');
change the second x-axis limits, then add a label
xlim([0.1 1.1]);
xlabel('Outer diameter, in');
See that the label is outside of the figure box. Also, changing 'OuterPosition' and 'InnerPosition' properties does't do anything

채택된 답변

MathWorks Support Team
MathWorks Support Team 2018년 6월 4일
When set the labels, MATLAB will rescale the axes to fit the labels onto the figure. However, when set the position of 'ax2', that position will take precedence over any rescaling that MATLAB usually does and this is why the label was out of the figure box.
To avoid this issue, first set the 'xlabel' for 'ax2' to scale appropriately and then call:
>> ax2_pos = ax2.Position;
>> ax1.Position = ax2_pos;

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Axis Labels에 대해 자세히 알아보기

태그

제품


릴리스

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by