フィルターのクリア

How to save figure in pdf without margins?

112 ビュー (過去 30 日間)
Mr M.
Mr M. 2018 年 7 月 21 日
コメント済み: André de Castro 2019 年 12 月 19 日
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' ?

回答 (1 件)

Jan
Jan 2018 年 7 月 22 日
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 件のコメント
Jan
Jan 2019 年 12 月 9 日
Did you try the -loose flag in the print command?
'-loose' — Use a loose bounding box. EPS and PS files only.
André de Castro
André de Castro 2019 年 12 月 19 日
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.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeAnnotations についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by