How to save a MATLAB graphic in a right size .pdf?
399 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
weijie
el 3 de Ag. de 2011
I save a graphic as .pdf format, but matlab will produce an A4 size to put this small picture in the middle of this A4 size pdf. The problem comes when I import them into my LaTeX file, i only need the picture size, not the whole A4 pdf size. Could anyone tell how to solve this problem?
2 comentarios
Bruce Rodenborn
el 10 de Nov. de 2024 a las 12:32
I absolutely cannot understand why thid BUG in MATLAB has not been fixed. I started using MATLAB in the aughts and have always had to save as an EPS and then convert to PDF. It is ridiculous for Mathworks to pretend like this is not a problem. Why would anyone want a PDF that is not formatted to be the same as the figure by default?
DGM
el 10 de Nov. de 2024 a las 16:40
Editada: DGM
el 10 de Nov. de 2024 a las 16:41
It makes sense to me that print()'s default behavior is to cater to output on paper.
Of course we're free to expect a different size, but what is the size of a figure in inches/centimeters/points? It's a function of whatever the presumed physical display resolution is, which varies with OS and version -- independently of what the apparent rendered size is. It's a baked-in ambiguity that means the size we get doesn't correspond to what we see on screen or what we expect to see when we embed it in another document.
% windows: 96
% mac: 72
% linux: varies (observed: R2009b-90; R2019b-96)
res = get(0,'ScreenPixelsPerInch') % R2024b
Like a lot of things, the expectations of figure capture are not universal. As a consequence, it's frequently tedious to do all the setup the way you want it. If you want it to always behave in a particular non-default way, just write a helper function or two to make life easier.
I don't know what the behavior of exportgraphics() is. I don't run a new enough version to know if that's of any convenience.
Respuesta aceptada
Friedrich
el 3 de Ag. de 2011
Hi,
you can do it in MATLAB through:
h = figure;
plot(1:10);
set(h,'Units','Inches');
pos = get(h,'Position');
set(h,'PaperPositionMode','Auto','PaperUnits','Inches','PaperSize',[pos(3), pos(4)])
print(h,'filename','-dpdf','-r0')
8 comentarios
MAzharul Islam
el 14 de Abr. de 2022
how to get it done while exporting simulink model using print. I write the following line in my command window which gives me a full page pdf instead of croped one. But in case of other formats it produces just the figure without any white space around the figure.
print('-shomedata','-dpdf','home.pdf')
Más respuestas (2)
Fereidani Samani
el 19 de Sept. de 2018
Editada: Walter Roberson
el 20 de Sept. de 2018
h4=figure;
set(h4,'PaperSize',[20 10]); %set the paper size to what you want
print(h4,'filename','-dpdf') % then print it
Oliver Woodford
el 3 de Ag. de 2011
Export_fig saves the figure at the dimensions it appears at on screen, and crops the whitespace around the figure, for a tight border.
Note that for exporting to pdf it requires that you have ghostscript installed.
1 comentario
SteveC
el 29 de Abr. de 2018
Using print or export_fig as above crop the figure, but change the fonts used in the figure. Printing to Adobe pdf can preserve the fonts by embedding them and crops the picture to the minimum size if Friedrich's setting are mode. (System: Adobe Acrobat Pro 2017, Matlab 2012b, Win 7 x64). This is much better for my application. Is there a way to have ghostscript embed the fonts in the pdf?
Ver también
Categorías
Más información sobre Printing and Saving en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!