How to add a description text on top of a plot without it being written all of my plot
48 views (last 30 days)
Show older comments
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');
2 Comments
Adam Danz
on 10 May 2019
I formatted your code. In the future, please use the formatting tools to add code. Thanks.
Accepted Answer
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');
2 Comments
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.
More Answers (0)
See Also
Categories
Find more on Annotations 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!