Saving tightly cropped PDFs in Matlab

8 visualizzazioni (ultimi 30 giorni)
Theo
Theo il 21 Lug 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?

Risposta accettata

Oleg Komarov
Oleg Komarov il 21 Lug 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 Commenti
Theo
Theo il 21 Lug 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 il 21 Lug 2011
See edit first line.

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Printing and Saving in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by