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

48 visualizzazioni (ultimi 30 giorni)
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');

Risposta accettata

Adam Danz
Adam Danz il 10 Mag 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 Commenti
Abdelhakim Souit
Abdelhakim Souit il 10 Mag 2019
Thank you it worked. but any idea how to make it so that the plots size stays the sames
Adam Danz
Adam Danz il 10 Mag 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.

Accedi per commentare.

Più risposte (0)

Community Treasure Hunt

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

Start Hunting!

Translated by