Increase the height (size) of subplots

918 vues (au cours des 30 derniers jours)
David E.S.
David E.S. le 6 Nov 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?

Réponses (3)

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

Chris
Chris le 6 Nov 2021
Modifié(e) : Chris le 6 Nov 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 le 6 Nov 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 commentaire
Guilherme Weber Sampaio de Melo
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!

Connectez-vous pour commenter.

Catégories

En savoir plus sur Startup and Shutdown dans Help Center et File Exchange

Produits


Version

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by