How to move title text to front of plot area

196 ビュー (過去 30 日間)
N. Fernandez
N. Fernandez 2022 年 1 月 31 日
編集済み: Arif Hoq 2022 年 1 月 31 日
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
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
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
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

Arif Hoq
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])

カテゴリ

Help Center および File ExchangeTitle についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by