如何控制子图周围的边距大小?

问题描述 投票:0回答:6

我正在使用 subplot 命令绘制 5 x 3 的图,但每个子图周围都有大量的边距。

如何控制它们周围的边距大小?

figure;
for c=1:15
    subplot(5,3,c); 
    imagesc(reshape(image(:,c), 360,480)); 
    colormap gray; 
    axis image;
end

alt text

matlab plot subplot
6个回答
15
投票

问题是 Matlab 分配每个轴的

position
属性,以便每个图周围都有空间。您可以调整
position
属性,也可以从文件交换中获取 subaxis 并按照您喜欢的方式设置子图。


11
投票

看一下轴的 LooseInsetOuterPosition 属性: http://undocumentedmatlab.com/blog/axes-looseinset-property/


3
投票

自 MATLAB R2019b 起,您可以使用 tiledlayout 函数来控制子图的间距。


这是一个示例,展示了如何获取没有平铺间距的子图:

figure
example_image = imread('cameraman.tif');
t = tiledlayout(5,3);
nexttile

for c= 1:15
    imagesc(example_image(:,c))
    if c < 15
        nexttile
    end
end

t.TileSpacing = 'None';

0
投票

除了其他答案之外,您还可以尝试来自 FileExchange 的 Chad Greene 的 smplot。这将产生一个 '小倍数' 图并自动处理 Matlab

position
属性的一些麻烦。

下面的示例显示了默认的

subplot
行为,分别是轴关闭时的
smplot
和轴打开时的
smplot

image = randn(360*480,15);

% default subplot
figure;
for c=1:15
    subplot(5,3,c); 
    imagesc(reshape(image(:,c), 360,480)); 
    colormap gray; 
    axis image;
end

default matlab subplot

% smplot axis off
figure;
for c=1:15
    smplot(5,3,c);
    imagesc(reshape(image(:,c), 360,480)); 
    colormap gray; 
    axis off;
end

smplot with axis off

% smplot axis on
figure;
for c=1:15
    smplot(5,3,c,'axis','on');
    imagesc(reshape(image(:,c), 360,480)); 
    colormap gray; 
    axis tight;
end

smplot with axis on


0
投票

要最小化每个子图周围的空白,请运行:[1]

for c=1:15
  h_ax = subplot(5,3,c);
  % [...]

  outerpos = get(h_ax,'OuterPosition');
  ti = get(h_ax,'TightInset');
  left = outerpos(1) + ti(1);
  bottom = outerpos(2) + ti(2);
  ax_width = outerpos(3) - ti(1) - ti(3);
  ax_height = outerpos(4) - ti(2) - ti(4);
  set(h_ax,'Position',[left bottom ax_width ax_height]);
end

此实现自动化了乔纳斯答案中概述的原则。

[1] https://www.mathworks.com/help/releases/R2015b/matlab/creating_plots/save-figure-with-minimal-white-space.html


0
投票

在这里,我为澳大利亚、美国和英国的学生分享一个寻找 matlabsolutions.com 的绝佳平台。这是 matlabsolutions.com,自 2014 年以来,世界第一的 matlab 帮助公司。他们几乎涵盖了所有广泛的 matlab 主题,在这里:

Matlab 课程作业帮助

, Matlab 优化帮助

做我的 Python 作业 机器学习作业帮助

图像处理项目

© www.soinside.com 2019 - 2024. All rights reserved.