필터 지우기
필터 지우기

Exported PDF figures have inaccurate dimensions

조회 수: 8 (최근 30일)
biggs
biggs 2015년 7월 30일
편집: Dario Mangoni 2016년 8월 12일
Example code (copied from a stackoverflow question):
%# create some plot, and make axis fill entire figure
plot([0 5 0 5], [0 10 10 0]), axis tight
set(gca, 'Position',[0 0 1 1])
%# set size of figure's "drawing" area on screen
set(gcf, 'Units','centimeters', 'Position',[0 0 5 10])
set(gcf, 'PaperPositionMode','auto')
%# save as TIFF
print -deps out.eps
Based on this code, the surrounding box should be exactly 50mm by 100mm. Instead, when I open the exported eps file in Illustrator and measure the surrounding box, it is 49.742mm by 100.189mm. This may seem nitpicking, but it is important because I need to overlay figures, some of which were generated in different programs. The different figures don't overlay nicely unless the dimensions are exact.
Is there any way to make matlab export exact dimensions? I normally use the function "export_fig", but it gives the same result as matlab's built-in "print" function, which makes me think this issue is a limitation of matlab.
  댓글 수: 3
biggs
biggs 2015년 7월 30일
Thanks for the suggestion. I tried:
set(gcf, 'PaperUnits','centimeters', 'PaperPosition',[0 0 5 10])
But my outputted eps file wasn't any different. Is this what you were suggesting?
Brendan Hamm
Brendan Hamm 2015년 7월 31일
Yes. I was not sure that this would work. I have never had stringent conditions on the actual output size of an .eps file. These were usually just input into LaTeX where they can be resized. This may be an issue with .eps graphics in general, as the whole concept is that it is a set of instructions to draw the image rather than pixels. Briefly viewing the help on the Illustrator website it seems there may be an issue with loading eps files created outside of Illustrator: https://helpx.adobe.com/illustrator/using/importing-eps-dcs-autocad-files.html

댓글을 달려면 로그인하십시오.

답변 (1개)

Dario Mangoni
Dario Mangoni 2016년 8월 12일
편집: Dario Mangoni 2016년 8월 12일
I had a quite similar problem. In my case all works fine with certain PaperSize (such as those of A4 paper), but when I print on A3 everything get crazy and dimensions are no more accurate. Works fine also with B4, usletter, A5 and smaller... But not with B3, B2 and bigger... I have a 17" 16:9 display (38cm x 21.5) and look at this: everything looks good until I stay under 22cm of height then the dimensions are not correct anymore... That's funny
Another strange issue is that the size of the figure on the display affects the output of the print command although PaperPositionMode is set to manual... I think that this issue is related to the first one...
(Moreover, while printing subsequently more pages I often find that some commands (like axes tightening) aren't effective except if I force the drawnow after every command)
This is my code. Simply changing from A4 to A3 I get two different solutions (that you can find in the attachment). As you can see the dimensions are correct in the A4 paper, but no more in the A3, where also axes Position gives strange results.
margins = [1 1]; % x and y margins of the plot area (axes) respect to the page borders
fig_h = figure('Visible','off');
ax_h = axes;
%%make whatever you want
plot([1 1 1 2 2 2 3 3 3 50],[1 2 3 1 2 3 1 2 3 50],'r*')
%%set the print page
drawnow
grid(ax_h,'on');
axis(ax_h,'equal');
drawnow
axis(ax_h,'tight');
drawnow
set(ax_h,'units','centimeters')
set(fig_h,'units','centimeters')
set(fig_h,'PaperUnits','centimeters')
set(fig_h,'MenuBar','none','ToolBar','none')
set(fig_h,'PaperType','a4')
set(fig_h,'PaperOrientation','landscape')
% set(fig_h,'PaperSize',[15 10]) %%for custom paper size
paper_size = get(fig_h,'PaperSize');
set(fig_h,'PaperPositionMode','manual')
set(fig_h,'PaperPosition',[0 0 paper_size(1) paper_size(2)]) % set position&size of the figure on the paper
% setting the position and size of the figure on the display shouldn't be necessary
% since PaperPositionMode is set to 'manual'; but otherwise it doesn't work ...
set(fig_h,'Position',[0 0 paper_size(1) paper_size(2)])
set(ax_h,'XLimMode','manual','YLimMode','manual')
set(ax_h,'FontSize',8)
xl = get(ax_h,'XLim');
yl = get(ax_h,'YLim');
axes_size = paper_size-2*margins;
set(ax_h,'Position',[margins axes_size])
set(ax_h,'XLim',[xl(1) xl(1) + axes_size(1)]) % make the axis match the effective dimension of the page
set(ax_h,'YLim',[yl(1) yl(1) + axes_size(2)])
set(ax_h,'XTick',xl:1:xl(1) + axes_size(1)) % set ticks every cm
set(ax_h,'YTick',yl(1):1:yl(1) + axes_size(2))
print(fig_h,'panel_draw.pdf','-dpdf')

카테고리

Help CenterFile Exchange에서 Printing and Saving에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by