How to add a description text on top of a plot without it being written all of my plot

조회 수: 48 (최근 30일)
How to add a description text on top of a plot without it being written all of my plot ?
here is my code just run it to understand what I mean.
is it possible to translate the plot to the bottom?
FigH = figure;
plot(1:10)
AxesH = axes('Parent', FigH, ...
'Units', 'normalized', ...
'Position', [0, 0, 1, 1], ...
'Visible', 'off', ...
'XLim', [0, 1], ...
'YLim', [0, 1], ...
'NextPlot', 'add');
chr = 'I wanna add a description';
chr = [chr newline 'On top of the plot']
TextH = text(0,1, chr , ...
'HorizontalAlignment', 'left', ...
'VerticalAlignment', 'top');

채택된 답변

Adam Danz
Adam Danz 2019년 5월 10일
Why not just reduce the height of your first axes a little? See the comments below (I also made some additional improvements).
FigH = figure();
axh = axes(FigH);
axh.Position(4) = axh.Position(4) * .9; % <--- reduce height by 10%
plot(axh, 1:10)
AxesH = axes('Parent', FigH, ...
'Units', 'normalized', ...
'Position', [0, 0, 1, 1], ...
'Visible', 'off', ...
'XLim', [0, 1], ...
'YLim', [0, 1], ...
'NextPlot', 'add');
chr = sprintf('I wanna add a description\nOn top of the plot');
TextH = text(AxesH, 0,1, chr , ...
'HorizontalAlignment', 'left', ...
'VerticalAlignment', 'top');
190510 080203-Figure 1.jpg
  댓글 수: 2
Abdelhakim Souit
Abdelhakim Souit 2019년 5월 10일
Thank you it worked. but any idea how to make it so that the plots size stays the sames
Adam Danz
Adam Danz 2019년 5월 10일
There's no way to create space out of nothing; the space has to come from somewhere. You could make the text one line, you could decrease the font size of the text; but there's no way I can imagine that creates space for your text without changing the axis size.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Annotations에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by