【问题标题】:How to avoid figure cropping in older versions of Matlab如何避免在旧版本的 Matlab 中裁剪图形
【发布时间】:2016-03-31 14:47:44
【问题描述】:

在回答问题Matlab figure to pdf: measuring accuracy 并从回答Limit of figure dimensions 中学习期间,出现了另一个问题。

当要调整大小的图形即将超出限制时,如何保护?

【问题讨论】:

    标签: matlab matlab-figure figure


    【解决方案1】:

    假设我们使用的是 matlab 2011b,屏幕分辨率为 1400 x 900 px,分辨率为 96 ppi,我们想要导出一个大小为 10" x 20" 的图形,这肯定超出了限制。

    FigureSize=[10 20];
    FigureInchSize=FigureSize.*1;           %\ Convert the given size to inches
    ScrSize=get(0,'ScreenSize');
    ScrSize=ScrSize(3:4);
    PPI_def=get(0,'ScreenPixelsPerInch');
    PPI_new=PPI_def;
    
    %\\ Calculate the appropriate resolution PPI_new
    if FigureSize(1)*PPI_new>ScrSize(1)    %\ Will the figure width exceed the limit?
      PPI_new=floor(ScrSize(1)/FigureInchSize(1));
    end
    if FigureSize(2)*PPI_new>ScrSize(2)    % Will the figure height exceed (new) limit?
      PPI_new=floor(ScrSize(2)/FigureInchSize(2));
    end
    
    set(0,'ScreenPixelsPerInch',PPI_new);
    set(FigureHandle,'position',[0.1,0.1,FigureSize]);
    %\\ Export the figure
    export_fig('Foo','-pdf','-nocrop');
    %\\ Reset the resolution
    set(0,'ScreenPixelPerInch',PPI_def);
    

    在第一部分,我们读取必要的值并将它们转换为合适的格式。我们还避免通过 set(Handle,'Units',<Units>) 进行自动转换,这可能会干扰对 Position 值的解释。

    在第二部分中,如果需要,我们会更改分辨率值。

    在第三部分我们更改分辨率,调整大小并导出图形,并将分辨率恢复为默认值。

    小心何时以及如何定义图形的布局。

    【讨论】:

      猜你喜欢
      • 2013-03-08
      • 2014-11-24
      • 2011-05-22
      • 2015-01-13
      • 2014-08-03
      • 2012-03-30
      • 2017-08-09
      • 2016-12-05
      相关资源
      最近更新 更多