删除轴时,MATLAB PDF输出不正确

时间:2014-01-06 17:53:56

标签: matlab pdf postscript

我正在尝试从数字生成PDF文件,以便在MATLAB中进行缩放。我试图隐藏图中的轴,因为我基本上只是画了一堆矩形(棋盘)。每当我尝试隐藏轴(set(gca,'Visible','off');axis off;)时,PDF输出似乎被剪切(我的棋盘显示中只有一个矩形)。任何想法为什么要关闭轴都搞砸了?

这是代码 - 我只是想生成一个可以扩展的棋盘

% Create a figure to get paper sizes
clear all;
clf;

% Use centimetres
set(gcf,'PaperUnits','centimeters');

% Get the paper dimensions
dims = get(gcf,'PaperSize');

inner_corner_x = 8;
inner_corner_y = 11;
margin = 2.5; % cm
dims = dims - 2*margin;

sz = round(min((dims(1)) / (inner_corner_x + 2), (dims(2)) / (inner_corner_y + 2)));

for i = 0:inner_corner_y
    for j = 0:inner_corner_x
        if mod(i + j, 2) == 0
            color = 'k';
        else
            color = 'w';
        end
        rectangle(...
            'Position', [j * sz i * sz sz sz],...
            'FaceColor', color,...
            'EdgeColor', color);
    end
end

% PROBLEM IS HERE
% Comment this line out to have ugly output, but at least all chessboard blocks show...
axis off;

set(gca,'LooseInset', get(gca,'TightInset'));
set(gcf,'PaperPositionMode','manual');
set(gcf,'PaperPosition',[margin margin dims]);

print -dpdf figure1

1 个答案:

答案 0 :(得分:2)

我最终手工编写了一个PostScript文件来生成棋盘。此特定脚本生成8.5“x 11”纸张大小的PDF,其中包含7x9个盒子。你用盒子设置盒子大小(在这种情况下是72“)。抱歉,这个答案与问题无关,但我真的无法得到我想要的这么简单的数字,所以我手动完成了并且效果很好。

%!PS
/ptsx 8.5 72 mul def
/ptsy 11  72 mul def
/boxx 7 def
/boxy 9 def
/sz 72 def

boxx sz mul ptsx gt {(Size too wide for page!) print quit} if
boxy sz mul ptsy gt {(Size too tall for page!) print quit} if

/marginx ptsx boxx sz mul sub 2 div def
/marginy ptsy boxy sz mul sub 2 div def

0 0 0 setrgbcolor
marginx marginy translate

/xval 0 def
/yval 0 def
/xon true def
/yon true def
0 1 boxy 1 sub {
  0 1 boxx 1 sub {
    newpath
    xval yval moveto
    xval yval sz add lineto
    xval sz add yval sz add lineto
    xval sz add yval lineto
    xon {fill} if
    /xval xval sz add def
    /xon xon not def
  } for
  /xval 0 def
  /yval yval sz add def
  /yon yon not def
  /xon yon def
} for