How to save figure in pdf without margins?
124 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Let us suppose I have a figure with definite pixel size:
set(gcf,'unit','pixel','position',[0 0 figure_width figure_height])
I would like to save it as a pdf. I know the aspect ratio, but how to set the size? I don't want unnecessary margins. I want to use something like this
set(gcf,'PaperPositionMode','auto','papersize',[a*figure_width a*figure_height]);
%print(gcf,'Fig','-dpdf','-r0')
But how to choose the value of 'a' ?
0 Kommentare
Antworten (1)
Jan
am 22 Jul. 2018
The value of a depends on the wanted size of the PDF. You can choose it freely to what you need. To remove the border use:
print(gcf, 'Fig.pdf', '-dpdf', '-fillpage')
3 Kommentare
Jan
am 9 Dez. 2019
Did you try the -loose flag in the print command?
'-loose' — Use a loose bounding box. EPS and PS files only.
André de Castro
am 19 Dez. 2019
Using -loose did improve the results. It worked for PDF, EPS and PS files. I also had to:
- not use -fillpage;
- set the Position property before printing, as below.
width = 3.5;
height = 2.2;
figure_handle.Units = 'inches';
figure_position = figure_handle.Position;
figure_handle.Position = [figure_position(1),figure_position(2), width, height];
It seems strange that I had to set the figure Position though, as I had already set PaperUnits and PaperSize appropriately.
Combining -loose and the above code with the solution suggested here, in the Expand Axes to Fill Figure section, gave even better results, cropping as close as possible to the drawn area. Said solution was not effective when I had tried it before because I was using -fillpage.
Siehe auch
Kategorien
Mehr zu Printing and Saving finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!