我经常需要一起绘制10张图像,但是使用此代码会导致图像变小:
img = rand(400,600);
for i=1:10
subplot(2,5,i);
imshow(img);
title(['Image ' int2str(i)]);
end
如您所见,图像并未使用屏幕上的所有可用空间。如何增加大小,或减少它们之间的填充/边距?
谢谢你的帮助。
我不认为有简单的方法可以做到。有两种选择:
首先,使用子图的位置部分:
>> subplot(2,5, i, [l, b, w, h])
并计算左,下,宽,高。
或者,获取返回轴的句柄:
>> h(i) = subplot(2,5,i);
然后修改轴。
>> set(h(1), 'position', [l, b, w, h] );
有许多页面会提供更多详细信息,例如,http://www.briandalessandro.com/blog/how-to-make-a-borderless-subplot-of-images-in-matlab/
[更新]
下面的代码提供了更多有关您可以做什么的信息,例如您要寻找的东西。这有点乏味。0.95和0.02只是提供了一些填充。他们没什么神奇的。:-)
要注意的另一件事是,我真的鼓励您使用“ ii”作为索引变量(或其他),因为“ i”的定义为sqrt(-1)。最好不要使用“ i”和“ j”作为索引变量(尤其是在Matlab中)。
img = rand(400,600);
figure(1);
clf();
hold on;
% Get the width and height of the figure
lbwh = get(1, 'position');
figw = lbwh(3);
figh = lbwh(4);
% Number of rows and columns of axes
ncols = 5;
nrows = 2;
% w and h of each axis in normalized units
axisw = (1 / ncols) * 0.95
axish = (1 / nrows) * 0.95
for ii=1:10
% calculate the row and column of the subplot
row = floor( ii/(ncols+1) ) + 1
col = mod( ii-1, ncols ) + 1
% calculate the left, bottom coordinate of this subplot
axisl = (axisw+0.02) * (col-1)
axisb = (axish+0.02) * (row-1)
% plot the subplot
h= subplot('position', [axisl, axisb, axisw, axish] );
imshow(img);
title(['Image ' int2str(ii)]);
pause
end
您将不得不使用它,以使其完全按照您的要求进行。而“帮助”是您的朋友。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句