Saving tightly cropped PDFs in Matlab

14 vues (au cours des 30 derniers jours)
Theo
Theo le 21 Juil 2011
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?

Réponse acceptée

Oleg Komarov
Oleg Komarov le 21 Juil 2011
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 commentaires
Theo
Theo le 21 Juil 2011
@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 le 21 Juil 2011
See edit first line.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Printing and Saving dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by