How to move title text to front of plot area
203 views (last 30 days)
Show older comments
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 Comments
Ankit
on 31 Jan 2022
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
on 31 Jan 2022
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)')
Answers (2)
Ankit
on 31 Jan 2022
Edited: Ankit
on 31 Jan 2022
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 Comments
Arif Hoq
on 31 Jan 2022
Edited: Arif Hoq
on 31 Jan 2022
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 Comments
See Also
Categories
Find more on Title in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!