Why axis labels disappear when trying to assign their position?
46 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Pouya Jamali
am 18 Jan. 2014
Kommentiert: alok dhaundiyal
am 16 Nov. 2020
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 Kommentare
Akzeptierte Antwort
Amit
am 19 Jan. 2014
Bearbeitet: Amit
am 19 Jan. 2014
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 Kommentare
Amit
am 19 Jan. 2014
Bearbeitet: Amit
am 19 Jan. 2014
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.
alok dhaundiyal
am 16 Nov. 2020
Ok, Mr Amit
Tell me how to bring back the colored axis back to plot, which get disappered after rescaling x, y, and z.
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Environment and Settings finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!