MATLAB图像顶部和底部的标题

use*_*033 2 matlab plot matlab-figure

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

Ben*_*_11 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');
Run Code Online (Sandbox Code Playgroud)

看起来像这样:

在此输入图像描述

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

最后,如果要在底部放置文本以创建图例,则可能需要将该属性设置'HorizontalAlignment'回其默认的"左".

这是你的想法吗?