Increase the height (size) of subplots

885 visualizzazioni (ultimi 30 giorni)
David E.S.
David E.S. il 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?

Risposte (3)

Walter Roberson
Walter Roberson il 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 il 6 Nov 2021
Modificato: Chris il 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 il 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 Commento
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!

Accedi per commentare.

Categorie

Scopri di più su Startup and Shutdown in Help Center e File Exchange

Prodotti


Release

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by