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 Center および File ExchangeGraphics Object Properties についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by