How do I decrease the margins around the subplots in my figure in MATLAB?

1.151 visualizaciones (últimos 30 días)
I would like to decrease the white space around my plots because when I copy the figure to a Word document, the margins around the axes reduces the size of the plot and I often have to crop this space out in order to increase the plot's size.

Respuesta aceptada

MathWorks Support Team
MathWorks Support Team el 26 de Dic. de 2022
Editada: MathWorks Support Team el 26 de Dic. de 2022
From R2019b, you can minimize the space around the plots by using tiledlayout function.
For details, please see the following documentation.
- Saving and Copying Plots with Minimal White Space
If you use R2019a and earlier releases, please refer the following information:
The ability to set margins for subplots in a figure is not currently available in MATLAB. However, you may refer to the user-contributed functions "subaxis" or "subtightplot" at MATLAB Central that provides this functionality:
MATLAB Central is a common location for MATLAB users provided by MathWorks where they can share their MATLAB code and ideas.
Note that MathWorks does not guarantee or warrant the use or content of these submissions. Any questions, issues, or complaints should be directed to the contributing author.
  1 comentario
Eric Sargent
Eric Sargent el 9 de Dic. de 2020
Starting in R2019b, you can create a tiledlayout and set padding and spacing properties. This example creates a layout with no padding around the perimeter and minimal spacing between plots.
tiledlayout(2,2, 'Padding', 'none', 'TileSpacing', 'compact');
for i=1:4
nexttile
plot(rand(1,10));
end
Also, starting in R2020a, you can use the copygraphics to copy a tightly cropped version of your graphics and then paste it in Word.
copygraphics(gcf)

Iniciar sesión para comentar.

Más respuestas (2)

Jesús Lucio
Jesús Lucio el 12 de Feb. de 2015
Hi,
I know the question is very old, but it's still very interesting.
A simple way of doing what you want (change margins of subplots) is this:
pos = get(gca, 'Position');
pos(1) = 0.055;
pos(3) = 0.9;
set(gca, 'Position', pos)
to write just after you create each (sub)plot.
This way each plot is resized. 'Position' is the axis property (a 1 x 4 vector) with these fields:
[x y width height]
Obviously, you can change any of the four values to your best choice.
Jesus.

KAE
KAE el 20 de Ag. de 2021
You could try tiledlayout.

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by