Print figures with many subplots in A4 format or similar

98 views (last 30 days)
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 Comments
Jan
Jan on 16 Nov 2021
This is a strange paper size for DinA4:
fig.PaperSize=[29.7 29.7];
Gianluca Regina
Gianluca Regina on 16 Nov 2021
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.

Sign in to comment.

Accepted Answer

Gianluca Regina
Gianluca Regina on 22 Nov 2021
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')

More Answers (0)

Categories

Find more on Interactive Control and Callbacks in Help Center and File Exchange

Products


Release

R2020b

Community Treasure Hunt

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

Start Hunting!