Print figures with many subplots in A4 format or similar

조회 수: 106 (최근 30일)
Gianluca Regina
Gianluca Regina 2021년 11월 16일
답변: Gianluca Regina 2021년 11월 22일
Dear MatLab users,
I have several figures with 12 subplots (4 rows and 3 colums) which I want to print and/or save in a standard A4 format. The in-MatLab figures appear with squeezed axis, so I need at least an A4 format to get a good representation of the data. Now, I can use the user interface of the print preview and choose the properties I need, but I would like to code it, and there doesn't seem to be a "generate code" for the print preview options. I have read this thread (https://www.mathworks.com/matlabcentral/answers/593113-exporting-a-figure-including-multiple-subplots-into-high-resolution-pdf-or-svg) and tried several things, but I can't seem to find a good and consistent way to do it.
If I use the print command and its options, I lose the axis properties (I used xticklabels) and the labels are overlapped.
% e.g.
fig = gcf;
fig.PaperUnits = 'centimeters';
fig.PaperSize=[29.7 29.7];
fig.PaperPosition = [1 1 20 28];
fig.PaperType = 'a4' ;
fig.PaperOrientation = 'portrait' ;
print(fig,'test','-dpdf')
If I use the exportgraphics command I get good resolution, but it automatically uses an A3 format to fill the page.
exportgraphics(gcf,'test2.pdf','ContentType','vector' , 'Resolution',600)
Thus, what is the most consistent way to print figures with these type of issues?
  댓글 수: 2
Jan
Jan 2021년 11월 16일
This is a strange paper size for DinA4:
fig.PaperSize=[29.7 29.7];
Gianluca Regina
Gianluca Regina 2021년 11월 16일
Indeed, I made a mistake, the correct size would be 21 29.7. However, it appears that the problem is the position value. I can put the dimensions I need (e.g. [1 1 20 25]) but I still have the axis tick problem.
I had a warning:
"Warning: The figure is too large for the page and will be cut off. Resize the figure, adjust the output size by setting the figure's PaperPosition property, use the 'print' command with either the '-bestfit' or '-fillpage' options, or use the 'Best fit' or 'Fill page' options on the 'Print Preview' window.
I tried that already but it doesn't work.
Again, I can fix those issues in print preview with user interface, but I cannot seem to do it by coding.

댓글을 달려면 로그인하십시오.

채택된 답변

Gianluca Regina
Gianluca Regina 2021년 11월 22일
To answer my own question, the XTicks and axis properties must be initialized in each subplot, and this type of configuration seems to work well.
set(gcf,'papertype','A4');
fig = gcf;
fig.PaperSize=[21 29.7];
fig.PaperPosition = [1 1 20 25];
print(fig,'test','-dbmp' , '-r300')

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Interactive Control and Callbacks에 대해 자세히 알아보기

제품


릴리스

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by