how can I change the distance between the axis and their title?

조회 수: 117 (최근 30일)
Mohammad
Mohammad 2014년 1월 21일
댓글: AJ von Alt 2014년 1월 21일
I want to change the distance between the axis and their title in a figure. is it possible?

채택된 답변

Mischa Kim
Mischa Kim 2014년 1월 21일
  댓글 수: 1
Mohammad
Mohammad 2014년 1월 21일
Thank you. the problem is that I don't know the position of the title cause user will enter different figures. this is my code, which doesn't seem to work.
h=hgload(name);
set(gcf,'paperunits','centimeters');
set(gcf,'paperposition',[w(1) w(2) a(1) a(1)*a(2)]);
textobj=findobj('type','text');
set(textobj,'fontunits','points');
set(textobj,'fontsize',w(3));
set(findall(gcf,'property','fontsize'),'fontsize',w(3));
set(gca,'fontsize',w(3));
set(findall(gca,'type','text'),'fontsize',w(3));
set(findall(gcf,'type','text'),'fontsize',w(3));
new_name=strrep([pathName name],'.fig','.png');
child=get(gcf,'children');
for y=1:length(child)
chi=child(y);
set(chi,'fontsize',w(3));
end
set(gca,'Units','centimeters');
pos=get(gca,'Position');
pos1=pos-[0 .02 0 0];
set(gca,'Position',pos1);

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

추가 답변 (1개)

AJ von Alt
AJ von Alt 2014년 1월 21일
편집: AJ von Alt 2014년 1월 21일
A title is a text object. You can change the position of any text object by using set to change the object's 'position' property value to a new vector. See the text properties documentation for more information.
Here is a quick demo where the title is moved to the left portion of the figure.
% move a title to the left
% create a figure and plot something
figure(1);
line;
% create a title and store its handle
th = title('blah');
% get the position of the title
titlePos = get( th , 'position');
% change the x value to 0
titlePos(1) = 0;
% update the position
set( th , 'position' , titlePos);
  댓글 수: 2
Mohammad
Mohammad 2014년 1월 21일
Thank you. the problem is that I don't know the position of the title cause user will enter different figures. this is my code, which doesn't seem to work.
h=hgload(name);
set(gcf,'paperunits','centimeters');
set(gcf,'paperposition',[w(1) w(2) a(1) a(1)*a(2)]);
textobj=findobj('type','text');
set(textobj,'fontunits','points');
set(textobj,'fontsize',w(3));
set(findall(gcf,'property','fontsize'),'fontsize',w(3));
set(gca,'fontsize',w(3));
set(findall(gca,'type','text'),'fontsize',w(3));
set(findall(gcf,'type','text'),'fontsize',w(3));
new_name=strrep([pathName name],'.fig','.png');
child=get(gcf,'children');
for y=1:length(child)
chi=child(y);
set(chi,'fontsize',w(3));
end
set(gca,'Units','centimeters');
pos=get(gca,'Position');
pos1=pos-[0 .02 0 0];
set(gca,'Position',pos1);
AJ von Alt
AJ von Alt 2014년 1월 21일
Those commands are changing the position of the axes object, not the title.
If you want to change the title object, you need to use the title handle as the first argument to set, not the axes handle.
Setting units to centimeters and changing the position by 0.2 mm doesn't do much. That is a really really small change. Unless you have a good reason to use centimeter units, I would recommend sticking with normalized units. Normalized units are much more intuitive. (0,0) is at the bottom left of the figure and (1,1) is at the top of the figure. An object at [0.25 0.5 1] would be 1/4 of the way from the left and 1/2 way from the bottom.
Try this code to give you an idea of how to modify the title position.
set(gca,'Units','normalized')
titleHandle = get( gca ,'Title' );
pos = get( titleHandle , 'position' );
pos1 = pos - [0 0.05 0]
set( titleHandle , 'position' , pos1 );

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

카테고리

Help CenterFile Exchange에서 Graphics Object Properties에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by