简体   繁体   English

Matlab - 创建不同大小子图的图形

[英]Matlab - Creating a figure of different sized subplots

I have an array of images and I need to plot them side by side, with each image having a different size.我有一组图像,我需要 plot 并排排列它们,每个图像具有不同的大小。 Although the actual image sizes are quite large, I would want to do something like imresize to plot the size that I want.虽然实际的图像尺寸很大,但我想做一些类似 imresize 到 plot 我想要的尺寸的事情。

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.非常感谢一些帮助。

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) .可以通过在语法 subplot subplot(m,n,p)中为网格 position 参数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]);

You can add 4 axeses to the figure, and set the position of each axes:您可以在图中添加 4 个轴,并设置每个轴的 position:

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.手动设置 position 不是最佳解决方案。
There must be a way to compute the position of each axes.必须有一种方法来计算每个轴的 position。

Result:结果:
在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM