【问题标题】:Printing figure at same size as figure window以与图形窗口相同的大小打印图形
【发布时间】:2012-04-30 23:29:30
【问题描述】:

我正在尝试以 PDF 格式保存一个图形,这样我就不会在它周围出现多余的空白,即图形应该与图形窗口的大小相同。

我很确定这样做的方法是

figureNames = {'a', 'b', 'c'};
for i = 1:3
    set(figure(i), 'paperpositionmode', 'auto');
    print(figure(i), '-dpdf', figureNames{i})
end

但它不起作用。我得到了和以往一样多的空白。有人能告诉我什么是错的吗?

【问题讨论】:

    标签: matlab printing figure


    【解决方案1】:

    您可以尝试将数字转换为 pdf 文件的“一体化”解决方案。我使用 mlf2pdf (http://www.mathworks.com/matlabcentral/fileexchange/28545),它似乎工作得很好。而且,由于所有东西都是乳胶排版,所以制作出来的人物质量要好得多

    【讨论】:

    • 在 MABLAB 文档中沉迷了一段时间后,我编写了一个小脚本来自动将纸张大小缩小到图形大小。现在一切正常。感谢您提供指向 MATLAB Central 文件的链接。
    【解决方案2】:

    我也遇到过这个问题。解决方法是打印-depsc(彩色)或-deps,如果您只需要灰度图。封装的 postscript 文件几乎没有白边。您可以稍后将 .eps 文件轻松转换为 pdf,如果您在 LaTeX 中工作,则可以按原样使用它。

    【讨论】:

    • 据我了解,EPS 是一种垂死的格式。很奇怪,为图形设置PaperPositionMode 会消除 EPS 文件的白边,而不是 PDF。
    【解决方案3】:

    似乎将PaperPositionMode 设置为auto 将消除EPS 文件的多余空白,但不是PDF。

    为了消除 PDF 的空白,我编写了一个小脚本来将纸张大小调整为图形大小。由于它很短,我将它包含在下面以防其他人需要它。

    它的灵感来自this document,以及这个StackOverflow question

    我的解决方案通过仅操作纸张大小而不是图形轴来工作,因为操作轴会遇到子图问题。这也意味着将保留 一些 空白。在 MATLAB 的词汇表中,这些数字的边界是 OuterPosition,而不是 TightInset

    function [filename] =  printpdf(fig, name)
    % printpdf Prints image in PDF format without tons of white space
    
    % The width and height of the figure are found
    % The paper is set to be the same width and height as the figure
    % The figure's bottom left corner is lined up with
    % the paper's bottom left corner
    
    % Set figure and paper to use the same unit
    set(fig, 'Units', 'centimeters')
    set(fig, 'PaperUnits','centimeters');
    
    % Position of figure is of form [left bottom width height]
    % We only care about width and height
    pos = get(fig,'Position');
    
    % Set paper size to be same as figure size
    set(fig, 'PaperSize', [pos(3) pos(4)]);
    
    % Set figure to start at bottom left of paper
    % This ensures that figure and paper will match up in size
    set(fig, 'PaperPositionMode', 'manual');
    set(fig, 'PaperPosition', [0 0 pos(3) pos(4)]);
    
    % Print as pdf
    print(fig, '-dpdf', name)
    
    % Return full file name
    filename = [name, '.pdf'];
    end
    

    【讨论】:

      猜你喜欢
      • 2016-11-25
      • 2012-10-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-06
      • 2011-06-16
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多