Why axis labels disappear when trying to assign their position?

In Matlab 2012b I need to move axis labels of my plot arbitrarily. I want this because they are not placed according to my taste by default. I tried the following workaround but I'm wondered why the label disappears no matter what the offset value is.
The modified complete code is:
clc;
clear all;
close all
x=0:0.01:10;
y=10*cos(x)+5*sin(10*x).^2;
fs=[4.5,1.5]; % figure size
%--------------------------------------------------------------------------
fh=figure;
set(fh,'Color','w')
set(fh,'Units','inches','Position',[3 3 fs])
set(fh,'PaperUnits','normalized','PaperSize',[1 1],'PaperPosition',[0 0 1 1])
ah=axes;plot(x,y,'Color',[1 0 0],'LineWidth',1)
hold on;
grid on;
box on
set(ah,'LineWidth',1)
set(ah,'FontName','Calibri','FontSize',10,'FontWeight','bold')
set(ah,'OuterPosition',[0 0 1.0 1.0])
xlh=xlabel('\itTime (s)','Units','normalized');
pos1=get(xlh,'Position');
pos1(1,2)=pos1(1,2)-0.05;
set(xlh,'Position',pos1)
ylh=ylabel('\ity_1');
What exactly want is to get xlabel a little bit closer to the axis. Something that I feel happening is that the label with it's position assigned manually will not be included in axis outer position region anymore. Am I right?

댓글 수: 2

Please provide some example data, such that we can reproduce your problem.
I did so Jan. Many thanks to your attention.

댓글을 달려면 로그인하십시오.

 채택된 답변

Amit
Amit 2014년 1월 19일
편집: Amit 2014년 1월 19일
I think you need to play with the size of your figure i.e. using 'Position' property along with 'OuterPosition'. Like, I tried this and I can see xlabel.
clc;
clear all;
close all
x=0:0.01:10;
y=10*cos(x)+5*sin(10*x).^2;
fs=[4.5,1.5]; % figure size
%--------------------------------------------------------------------------
fh=figure;
set(fh,'Color','w')
set(fh,'Units','inches','Position',[3 3 fs])
set(fh,'PaperUnits','normalized','PaperSize',[1 1],'PaperPosition',[0 0 1 1])
ah=axes;plot(x,y,'Color',[1 0 0],'LineWidth',1)
hold on;
grid on;
box on
set(ah,'LineWidth',1)
set(ah,'FontName','Calibri','FontSize',10,'FontWeight','bold')
set(ah,'OuterPosition',[0 0 1 1]);
set(ah,'Position',[0.15 0.3 0.8 0.5]); % This I what I added, You need to play with this
xlh=xlabel('\itTime (s)','Units','normalized');
pos1=get(xlh,'Position');
pos1(1,2)=pos1(1,2)-0.05;
set(xlh,'Position',pos1)
ylh=ylabel('\ity_1');
Nice mods though!!

댓글 수: 3

Thank you Amit. This works. However, the question of why that happens is remained unsolved.
Amit
Amit 2014년 1월 19일
편집: Amit 2014년 1월 19일
with your script, xlabel is there all the time, however it gets of the figure and you cant see it.
By default, MATLAB figure readjusts themselves once you resize the window. However, in your case you have fixed nearly all the size parameters. Thats why, when you decrease the figure size using 'Position', you relatively make space for the xlabel to appear.
Ok, Mr Amit
Tell me how to bring back the colored axis back to plot, which get disappered after rescaling x, y, and z.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터 및 File Exchange에서 Axis Labels에 대해 자세히 알아보기

제품

질문:

2014년 1월 18일

댓글:

2020년 11월 16일

Community Treasure Hunt

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

Start Hunting!

Translated by