Increase the height (size) of subplots

919 visualizaciones (últimos 30 días)
David E.S.
David E.S. el 6 de Nov. de 2021
Supposing the following code:
subplot(5,1,1)
plot(rand(10),rand(10),'-');
subplot(5,1,2)
plot(rand(10),rand(10),'-');
subplot(5,1,3)
plot(rand(10),rand(10),'-');
subplot(5,1,4)
plot(rand(10),rand(10),'-');
subplot(5,1,5)
plot(rand(10),rand(10),'-');
How can I increase the height of each one of the plots?

Respuestas (3)

Walter Roberson
Walter Roberson el 6 de Nov. de 2021
I see you are using R2019b. In your release, tiledlayout was introduced; people have been happier with that for adjusting spacing.

Chris
Chris el 6 de Nov. de 2021
Editada: Chris el 6 de Nov. de 2021
If you have 2019b or newer, you can use a tiledlayout. It doesn't really show here, but there's a difference.
tiledlayout(5,1,'TileSpacing','tight','Padding','tight')
for idx = 1:5
nexttile
plot(rand(10),rand(10),'-')
end
With subplots, you could grab the axes and adjust the Position property.
subplot(5,1,3)
ax = gca;
ax.Position(4) = 1.3*ax.Position(4)
You can also change the Position of the figure, to add more height overall
fig = gcf;
fig.Position(4) = 1.5*fig.Position(4)

Star Strider
Star Strider el 6 de Nov. de 2021
One approach —
figure
subplot(5,1,1)
plot(rand(10),rand(10),'-');
subplot(5,1,2)
plot(rand(10),rand(10),'-');
subplot(5,1,3)
plot(rand(10),rand(10),'-');
subplot(5,1,4)
plot(rand(10),rand(10),'-');
subplot(5,1,5)
plot(rand(10),rand(10),'-');
figure
subplot(5,1,1)
plot(rand(10),rand(10),'-');
subplot(5,1,2)
plot(rand(10),rand(10),'-');
subplot(5,1,3)
plot(rand(10),rand(10),'-');
subplot(5,1,4)
plot(rand(10),rand(10),'-');
subplot(5,1,5)
plot(rand(10),rand(10),'-');
pos = get(gcf, 'Position');
pos = 1×4
671 661 577 433
set(gcf, 'Position',pos+[0 -500 0 500])
This gets the 'Position' property of the parent figure and stretches the figure vertically, without otherwise altering its position or any of its other properties.
.
  1 comentario
Guilherme Weber Sampaio de Melo
Guilherme Weber Sampaio de Melo el 9 de Feb. de 2024
Hello. Thanks for that example to increase the subplots. Do you know how I can increase the space between them? I have a 1x7 figure (seven subplots) and some of the labels of the y-axis are overlapping. Another problem, its because four of them are color pictures with color bar and the subplots with colorbar keep a horizontal axis extension different of that wihout colorbar. Any help will be greatly appreciated!

Iniciar sesión para comentar.

Categorías

Más información sobre Startup and Shutdown en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by