【问题标题】:How to reduce the borders around subplots in matlab? [duplicate]如何减少matlab中子图周围的边界? [复制]
【发布时间】:2011-10-04 19:59:37
【问题描述】:

在 matlab 中,子图周围浪费了大量的空间。例如,在这个例子中:

t = 0:0.001:2*pi+0.001;
figure(2);
for i = 1 : 25;
    subplot(5,5,i);
    plot(t, sin(i*t));
    axis off
end

图上超过 50% 的空间被浪费为“空白” 我想缩小该空白空间,但未能成功确定这样做的机制。想法?

【问题讨论】:

标签: matlab subplot


【解决方案1】:

文件交换上的subaxis 函数允许您指定子图的边距。

示例用法:

t = 0:0.001:2*pi+0.001;
figure(2);
for i = 1 : 25;
    subaxis(5,5,i, 'Spacing', 0.03, 'Padding', 0, 'Margin', 0);
    plot(t, sin(i*t));
    axis tight
    axis off
end

【讨论】:

    【解决方案2】:

    您可以使用自己(或以编程方式)定位它们

    subplot('Position',[left bottom width height]);
    

    默认情况下,坐标是标准化的。所以一个位置 [0.1 0.1 0.5 0.5] 将从 10% 开始 从左下角开始,宽度相等 到图形宽度的一半,高度等于图形的一半 图高。

    有关边距和填充的内置解决方案,请参阅公认的答案。

    【讨论】:

      【解决方案3】:

      尝试减少隐藏轴LooseInsets属性中的默认值,如http://UndocumentedMatlab.com/blog/axes-looseinset-property/中所述

      例如:

      set(gca, 'LooseInset', get(gca,'TightInset'))
      

      【讨论】:

      • 至少在我的例子中,这对 2011a 没有任何作用。
      • 额外的空间被隐藏的 X & Y 轴刻度标签占用,我不相信它们可以被消除。但是您可以通过以下方式改善这种情况:figure(2); for i = 1 : 25; hax=axes(); plot(t, sin(i*t)); axis tight; axis off; rowIdx=fix((i-1)/5); colIdx=mod(i-1,5); newPos=[.2*colIdx,0.8-.2*rowIdx,.2,.2]; set(gca,'outer',newPos), end
      • LooseInset 是否适用于子图?
      猜你喜欢
      • 2012-11-08
      • 2012-08-23
      • 1970-01-01
      • 1970-01-01
      • 2011-05-23
      • 1970-01-01
      • 2015-06-05
      • 1970-01-01
      相关资源
      最近更新 更多