删除matlab子图中的间距
Remove spacing in matlab subplot
我应该如何删除这些图像之间的空白 space?我需要将所有这些图像组合起来,而不需要任何 space。
bot=imread('bot.jpeg');
for i= 1:25
subplot(5,5,i),imshow(bot);
end
最规范的方法是查看 bla here 的这个答案。此答案使用 MATLAB 文件交换中的函数来实现答案。然而,这需要学习一个新函数并使用参数。
如果您希望某些东西立即起作用,而不是在图上的单独网格中显示每个子图像,我会简单地创建一个将所有这些图像堆叠在一起的新图像:
bot_new = repmat(bot, [5 5]);
imshow(bot_new);
repmat
takes a matrix and duplicates / stacks / tiles itself together for as many rows and as many columns (or in any dimension) that you want. In this case, I chose to stack the image so that there are 5 rows and 5 columns of it. We next show the stacked image together with imshow
.
如果我们使用来自 MATLAB 的示例图像:
bot = imread('onion.png');
如果我们运行上面的代码将图像平铺在一起并显示图像,这就是我们得到的:
我从mathworks复制答案:
对于每个子图,存储其句柄。
h = subplot(2,3,1);
然后把h的'position' 属性设置成任何你想要的。
p = get(h, 'pos');
这是一个 4 元素向量 [left, bottom, width, height]
默认情况下是在归一化坐标(百分比
图 window)。例如,添加 0.05 个单位(5%
图 window) 到宽度,这样做:
p(3) = p(3) + 0.05;
set(h, 'pos', p);
SUBPLOT 命令为这些选择标准值
参数,但它们可以是你想要的任何东西。你
可以把轴放在你想要的图形的任何地方,
任何尺寸。
您可以检查一下:
http://www.mathworks.com/matlabcentral/newsreader/view_thread/144116
使用 subplot
创建轴时需要指定轴的 'Position'
属性。
此外,您必须调整图形纵横比以匹配图像的纵横比,以便所有图形都适合而不是垂直或水平space。
如果您在每个子图中显示不同的图像,所有图像应具有相同的纵横比,否则它们不可能在没有空 spaces 的情况下放入图中。
bot = imread('peppers.png');
for i= 1:25
subplot('Position',[(mod(i-1,5))/5 1-(ceil(i/5))/5 1/5 1/5])
imshow(bot); %// or show a different image on each subplot
end
p = get(gcf,'Position');
k = [size(bot,2) size(bot,1)]/(size(bot,2)+size(bot,1));
set(gcf,'Position',[p(1) p(2) (p(3)+p(4)).*k]) %// adjust figure x and y size
我应该如何删除这些图像之间的空白 space?我需要将所有这些图像组合起来,而不需要任何 space。
bot=imread('bot.jpeg');
for i= 1:25
subplot(5,5,i),imshow(bot);
end
最规范的方法是查看 bla here 的这个答案。此答案使用 MATLAB 文件交换中的函数来实现答案。然而,这需要学习一个新函数并使用参数。
如果您希望某些东西立即起作用,而不是在图上的单独网格中显示每个子图像,我会简单地创建一个将所有这些图像堆叠在一起的新图像:
bot_new = repmat(bot, [5 5]);
imshow(bot_new);
repmat
takes a matrix and duplicates / stacks / tiles itself together for as many rows and as many columns (or in any dimension) that you want. In this case, I chose to stack the image so that there are 5 rows and 5 columns of it. We next show the stacked image together with imshow
.
如果我们使用来自 MATLAB 的示例图像:
bot = imread('onion.png');
如果我们运行上面的代码将图像平铺在一起并显示图像,这就是我们得到的:
我从mathworks复制答案:
对于每个子图,存储其句柄。
h = subplot(2,3,1);
然后把h的'position' 属性设置成任何你想要的。
p = get(h, 'pos');
这是一个 4 元素向量 [left, bottom, width, height] 默认情况下是在归一化坐标(百分比 图 window)。例如,添加 0.05 个单位(5% 图 window) 到宽度,这样做:
p(3) = p(3) + 0.05;
set(h, 'pos', p);
SUBPLOT 命令为这些选择标准值 参数,但它们可以是你想要的任何东西。你 可以把轴放在你想要的图形的任何地方, 任何尺寸。
您可以检查一下: http://www.mathworks.com/matlabcentral/newsreader/view_thread/144116
使用 subplot
创建轴时需要指定轴的 'Position'
属性。
此外,您必须调整图形纵横比以匹配图像的纵横比,以便所有图形都适合而不是垂直或水平space。
如果您在每个子图中显示不同的图像,所有图像应具有相同的纵横比,否则它们不可能在没有空 spaces 的情况下放入图中。
bot = imread('peppers.png');
for i= 1:25
subplot('Position',[(mod(i-1,5))/5 1-(ceil(i/5))/5 1/5 1/5])
imshow(bot); %// or show a different image on each subplot
end
p = get(gcf,'Position');
k = [size(bot,2) size(bot,1)]/(size(bot,2)+size(bot,1));
set(gcf,'Position',[p(1) p(2) (p(3)+p(4)).*k]) %// adjust figure x and y size