Saving tightly cropped PDFs in Matlab

조회 수: 8 (최근 30일)
Theo
Theo 2011년 7월 21일
I'm sure many can empathize with my question:
I have a figure that needs to be saved in a pdf format (a) without axes or labels, and (b) in the tightest bounding box possible---that is, if the figure is with x and y limits on [-2, 2], then the final result should be a 2x2 box. No more, no less.
Unfortunately, Matlab makes it extremely difficult to do this, apparently. I have been using the excellent savefig program to try and bypass the bounding box issues. And then I try something like this:
x = linspace(-2,2,200); y = linspace(-2,2,200);
[xmat,ymat] = meshgrid(x,y);
z = xmat + 1i*ymat;
[C,h] = contourf(x,y,z.^2,30);
set(gca,'Visible','off')
savefig('mypdf', 'pdf');
However, the final output is a pdf with tight bounding boxes on the bottom and left, but there is a small whitespace on the right and top.
Can anybody tell me how to get rid of that whitespace?

채택된 답변

Oleg Komarov
Oleg Komarov 2011년 7월 21일
Make the axes slighly bigger:
Edit
% Create a figure measure in pixels positioned at 360 (from left) 150 (from bottom), 560 (long) and 420 (tall)
figure('units','pixels','position',[360 150 560 420])
axes('un','pix','pos',[0 0 570 430]);
x = linspace(-2,2,200); y = linspace(-2,2,200);
[xmat,ymat] = meshgrid(x,y);
z = xmat + 1i*ymat;
[C,h] = contourf(x,y,z.^2,30);
set(gca,'Visible','off')
savefig myfig pdf
  댓글 수: 2
Theo
Theo 2011년 7월 21일
@Oleg: This seems to work nicely, but I'm having trouble finding any documentation that explains what those two lines mean (un, pix, pos?). What do those numbers mean, too. Can you explain what it does?
Oleg Komarov
Oleg Komarov 2011년 7월 21일
See edit first line.

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

추가 답변 (0개)

카테고리

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