Increase the height (size) of subplots

889 Ansichten (letzte 30 Tage)
David E.S.
David E.S. am 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?

Antworten (3)

Walter Roberson
Walter Roberson am 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 am 6 Nov. 2021
Bearbeitet: Chris am 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 am 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 Kommentar
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!

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Startup and Shutdown finden Sie in Help Center und File Exchange

Produkte


Version

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by