How to move title text to front of plot area
조회 수: 153 (최근 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,
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/879635/image.png)
댓글 수: 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에서 Annotations에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!