【发布时间】:2013-11-23 19:01:55
【问题描述】:
我正在尝试使用我在这些问题中找到的答案:
- How to save a plot into a PDF file without a large margin around
- Get rid of the white space around matlab figure's pdf output
- External source
将 matlab 绘图打印到 pdf 而不包含白边。
但是使用此代码:
function saveTightFigure( h, outfilename, orientation )
% SAVETIGHTFIGURE(H,OUTFILENAME) Saves figure H in file OUTFILENAME without
% the white space around it.
%
% by ``a grad student"
% http://tipstrickshowtos.blogspot.com/2010/08/how-to-get-rid-of-white-margin-in.html
% get the current axes
ax = get(h, 'CurrentAxes');
% make it tight
ti = get(ax,'TightInset');
set(ax,'Position',[ti(1) ti(2) 1-ti(3)-ti(1) 1-ti(4)-ti(2)]);
% adjust the papersize
set(ax,'units','centimeters');
pos = get(ax,'Position');
ti = get(ax,'TightInset');
set(h, 'PaperUnits','centimeters');
set(h, 'PaperSize', [pos(3)+ti(1)+ti(3) pos(4)+ti(2)+ti(4)]);
set(h, 'PaperPositionMode', 'manual');
set(h, 'PaperPosition',[0 0 pos(3)+ti(1)+ti(3) pos(4)+ti(2)+ti(4)]);
% save it
%saveas(h,outfilename);
if( orientation == 1)
orient portrait
else
orient landscape
end
print( '-dpdf', outfilename );
end
这个输出的结果:
如您所见,“PaperSize”似乎设置不正确。对可能的修复有任何想法吗?
注意
如果我在landscape 和portrait 之间改变方向,结果是一样的,只是图像以不同的方式被切碎。
但是,如果我使用 saveas(h,outfilename); 指令保存图像,则会产生正确的输出。
这是为什么?两个保存指令有什么区别?
【问题讨论】:
-
我终于放弃了直接打印成pdf的尝试,开始打印成eps,需要的时候可以很方便的转换成pdf。
标签: image matlab pdf matlab-figure