Saving tightly cropped PDFs in Matlab

8 次查看(过去 30 天)
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?

请先登录,再进行评论。

更多回答(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