How to display lines of text/string in a subplot in MATLAB? -


i have set of subplots in figure in matlab. produce set of tests connected graphs in these subplots. have separate subplot presents these strings. not want annotate graph or produce graph prints text onto it. want print around 5 lines of text onto subplot.

i tried manually placing strings @ coordinates got messy. there straightforward approach?

use text() function, 'parent' property set handle of subplot, i.e.,

figure; h1 = subplot(2, 1, 1); % plotting on h1  h2 = subplot(2, 1, 2); text(0, 0, sprintf('%s\n%s\n%s ... etc', line1str, line2str, line3str), 'parent', h2); 

note here have passed return sprintf in order include newline characters in string (text accepts new lines , displays them without problem).

you may wish centre text in axes, replace first 2 arguments xpos, ypos, these are:

xl = xlim(h2);  xpos = xl(1) + diff(xl) / 2;  yl = ylim(h2);  ypos = yl(1) + diff(yl) / 2;  t = text(xpos, ypos, sprintf('%s\n%s\n%s ... etc', line1str, line2str, line3str), 'parent', h2); set(t, 'horizontalalignment', 'center'); 

the last line sets alignment center well.


Comments