How to move title text to front of plot area
201 次查看(过去 30 天)
显示 更早的评论
Hello,
I would like to move the title to inside the ploting area of my figure.
The title appears by default at the top of the plotting area and centered. To change title position I use:
title(['this is my title'])
set(get(gca,'title'),'Position', [x y z])
The problem is that the text of the title appers behind the plotted area. See attached figure. The title is only seen where it is above the plotting area. At the plotting area (which here is seen filled in white) the title is "hidden" behind.
How can I bring the title to the front of the plot area so that the text is visible on top of anything that is inside the plot area (white or any other filling colors)?
Thank you,
2 个评论
Ankit
2022-1-31
you problem is not clear.. are you using title() to define title of the group.. and it is not clear from your image what you are trying to do
Arif Hoq
2022-1-31
Did you try like this ?
x = linspace(0,10,150);
y = sin(x);
figure(1)
plot(x,y,'Color','r')
title('this is my title')
xlabel('x axis')
ylabel('sin(x)')
回答(2 个)
Ankit
2022-1-31
编辑:Ankit
2022-1-31
plot(rand(1,50));
t = title('this is my title', 'Units', 'normalized', 'Position', [0.5, 0.75, 0]);
t.Color = 'r'; t.FontSize = 10; % with this you can change color, font name and size
Another way to achieve this is with annotation, please see one such example. More Info: Create annotations - MATLAB annotation - MathWorks Deutschland
figure;
plot(rand(1,50));
dim = [.2 .5 .3 .3];
str = 'this is my title';
a = annotation('textbox',dim,'String',str,'FitBoxToText','on');
a.BackgroundColor = 'g'; % make the background color green
a.FaceAlpha = .2; % this will make translucent
0 个评论
Arif Hoq
2022-1-31
编辑:Arif Hoq
2022-1-31
this one should work. You have to adjust the position value.
x = linspace(0,10,150);
y = sin(x);
figure(1)
plot(x,y,'Color','r')
% title('this is my title')
xlabel('x axis')
ylabel('sin(x)')
title('this is my title', 'Units', 'normalized', 'Position', [.5, 1, 1]);
Or, try with this
x = linspace(0,10,150);
y = sin(x);
figure(1)
plot(x,y,'Color','r')
title('this is my title')
xlabel('x axis')
ylabel('sin(x)')
set(get(gca,'title'),'Position', [5 1 0])
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Title 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!