Print figures with many subplots in A4 format or similar

114 次查看(过去 30 天)
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 个评论
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