How to correctly plot a 6x2 grids of subplots

조회 수: 35 (최근 30일)
Tarek Hajj Shehadi
Tarek Hajj Shehadi 2021년 8월 4일
댓글: DGM 2021년 8월 4일
I have 6 images that I wish to plot them in a 6x2 grid of subplots.
I applied it as follow :
subplot(6,2,1)
%...
subplot(6,2,2)
%...
subplot(6,2,3)
%...
subplot(6,2,4)
%...
subplot(6,2,5)
%...
subplot(6,2,6)
%...
The issue is that MATLAB displayed a 6x2 grid of subplots but each image was extremelty small (about 1cm height in height and width). How can this be fixed?

채택된 답변

Rik
Rik 2021년 8월 4일
편집: Rik 2021년 8월 4일
You can also make a montage yourself.
The function below is from my unpublished toolbox replacement suite.
You still need an imshow after this call.
function I=noToolbox___montage(I,varargin)
%Slice up the image just as montage would have done.
%
%syntax:
% I=montage(I,'NoFigure',true)
%
% Setting the NoFigure to true will reshape the row*col*color*page input to a row2*col2*color
% image. The output has the same class as the input, and an attempt is made to preserve sparsity
% and complexity. The output is square, rounding up the number of columns when required, which
% follows the Matlab convention.
%
%Note that this doesn't actually replicate the montage function. Substantial edits are required to
%expand this code to be a full replacement.
if ~isequal(varargin,{'NoFigure',true})
error('HJW:montage:NotImplemented','Only one syntax is supported, see documentation.')
end
%The below code is equivalent to black=zeros(size(I,1:3),'like',I);
black=eval([class(I) '(0)']); %copy class
if issparse(I),black=sparse(black); end %copy sparsity
if ~isreal(I), black=complex(black);end %copy complexity
black=repmat(black, size(I,1),size(I,2),size(I,3) );
cols=ceil(sqrt(size(I,4)));rows=ceil(size(I,4)/cols);
I=mat2cell(I,size(I,1),size(I,2),size(I,3),ones(1,size(I,4)));
I=squeeze(I);
if numel(I)<(cols*rows)
I( (numel(I)+1) : (cols*rows))={black};
end
I=reshape(I,cols,rows)';%Flip for column-first to row-first.
I=cell2mat(I);
end
  댓글 수: 3
Rik
Rik 2021년 8월 4일
I don't use regionprops often enough myself. Here is the current header. I wonder if there might be issues publishing this. I don't look at the Mathworks implementation when creating these alternatives, I just read the doc and test a few syntax options. It is low enough priority that I doubt I will ever publish this separately. I did include some of them in a minified form in the supplementary materials of a paper.
function varargout=noToolbox__IPT(functionname,varargin)
%Wrapper function for the Image Processing toolbox replacement functions.
%
% The implementations in this function library are all aimed to replicate the toolbox functions on
% all releases (ML6.5 up to current release) without any toolbox requirement. Limitations will be
% mentioned in the respective doc. Not every syntax may be implemented.
%
% NOTE: this library is not intended to be drop-in replacement for the toolbox. Toolbox functions
% undergo a lot more testing, validation and optimization than is possible for a library like this.
% I would suggest using this in a try-catch block where you try the toolbox function first.
%
% syntax:
% [___]=noToolbox__IPT(functionname,___)
% noToolbox__IPT('help',functionname)
% The functionname must be a char array or a scalar string containing one of the implemented
% function names below.
%
% Functions:
% imopen
% imclose
% imdilate
% imerode
% bwlabel/bwlabeln
% bwdist
% montage
DGM
DGM 2021년 8월 4일
Fair nuff.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Chunru
Chunru 2021년 8월 4일
You can use montage which remove the gaps of subplot axes. doc montage for more details.
% fileNames is the string array of images
montage(fileNames, 'Size', [6 2);
  댓글 수: 2
Tarek Hajj Shehadi
Tarek Hajj Shehadi 2021년 8월 4일
편집: Tarek Hajj Shehadi 2021년 8월 4일
I unfortunately do not have the image processing tooblox
Chunru
Chunru 2021년 8월 4일
then you can use "tiledlayout" which has more control of the layout. Here is the example from doc.
t = tiledlayout(2,2,'TileSpacing','Compact');
% Tile 1
nexttile
plot(rand(1,20))
title('Sample 1')
% Tile 2
nexttile
plot(rand(1,20))
title('Sample 2')
% Tile 3
nexttile
plot(rand(1,20))
title('Sample 3')
% Tile 4
nexttile
plot(rand(1,20))
title('Sample 4')

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Lighting, Transparency, and Shading에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by