how can I change the distance between the axis and their title?
117 次查看(过去 30 天)
显示 更早的评论
I want to change the distance between the axis and their title in a figure. is it possible?
0 个评论
采纳的回答
更多回答(1 个)
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 个评论
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 Exchange 中查找有关 Graphics Object Properties 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!