MATLAB图像顶部和底部的标题

时间:2014-11-07 18:25:03

标签: matlab plot matlab-figure

我正在使用MATLAB子图绘制一行图形(图像,而不是图形)。我想在每个图像的顶部有一个标题,在底部有另一个标题。有没有办法做到这一点?

1 个答案:

答案 0 :(得分:6)

我会使用titletext注释的组合。基本上获得标题的位置,然后将其移动到图像下方,居中。好处是标题会自动放置在轴的顶部,因此您只需要获取其位置并应用移位来放置文本。

A = imread('pears.png');
B = imread('peppers.png');


figure;

subplot(1,2,1)

h1 = imshow(A);

[HeightA,~,~] = size(A);

hT1 = title('Pears at the top');

T1Pos = round(get(hT1,'Position')); %// Get the position

hT1_2 = text(T1Pos(1),T1Pos(2) + HeightA+50,'Pears at the bottom','HorizontalAlignment','center'); %// Place the text


subplot(1,2,2)
h2 = imshow(B);

[HeightB,~,~] = size(B);

hT2 = title('Peppers at the top');

T2Pos = round(get(hT2,'Position'));

hT2_2 = text(T2Pos(1),T2Pos(2) + HeightB+50,'Peppers at the bottom','HorizontalAlignment','center');

看起来像这样:

enter image description here

我使用50像素的移位,但你当然可以玩它。对于顶部的标题,您也可以使用文本注释,但在我看来使用标题函数有点简单,因为它本身就是顶部。

最后,如果您想在底部放置文字以创建图例,则可能需要将属性'HorizontalAlignment'设置回默认值' left'。

这是你的想法吗?

相关问题