Reputation: 2773
I have an array of images and I need to plot them side by side, with each image having a different size. Although the actual image sizes are quite large, I would want to do something like imresize to plot the size that I want.
I have tried doing the subplot strategy like
subplot(1, 4, 1);
imshow(...);
subplot(1, 4, 2);
imshow(...);
subplot(1, 4, 3);
imshow(...);
subplot(1, 4, 4);
imshow(...);
But all the images show up as the same size. I want something like this
This for some reason seems non-trivial. Would really appreciate some help.
Upvotes: 2
Views: 6349
Reputation: 32144
You can add 4 axeses to the figure, and set the position of each axes:
I = imread('cameraman.tif');
scrsz = get(groot, 'ScreenSize'); %Get screen size
f = figure('Position', [scrsz(3)/10, scrsz(4)/5, scrsz(4)/2*2.4, scrsz(4)/2]); %Set figure position by screen size.
positionVector1 = [-0.25, 0.95-0.9, 0.9, 0.9]; %position vector for largest image.
positionVector2 = [0.23, 0.95-0.6, 0.6, 0.6];
positionVector3 = [0.555, 0.95-0.4, 0.4, 0.4];
positionVector4 = [0.775, 0.95-0.267, 0.267, 0.267]; %position vector for smallest image.
axes(f, 'Position', positionVector1);
imshow(I, 'border', 'tight');
axes(f, 'Position', positionVector2);
imshow(I, 'border', 'tight');
axes(f, 'Position', positionVector3);
imshow(I, 'border', 'tight');
axes(f, 'Position', positionVector4);
imshow(I, 'border', 'tight');
Setting the position manually is not the best solution.
There must be a way to compute the position of each axes.
Upvotes: 2
Reputation: 124
It's possible to make subplots of different sizes by specifying a multiple-element vector for the grid position argument p
in the syntax subplot(m,n,p)
.
Your example can be constructed with the following:
subplot(4,10,[1:4 11:14 21:24 31:34]);
subplot(4,10,[5:7 15:17 25:27]);
subplot(4,10,[8:9 18:19]);
subplot(4,10,[10]);
Upvotes: 3