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

48 views (last 30 days)
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');

Accepted Answer

Adam Danz
Adam Danz on 10 May 2019
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 Comments
Adam Danz
Adam Danz on 10 May 2019
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.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!