Increase the height (size) of subplots
778 次查看(过去 30 天)
显示 更早的评论
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?
0 个评论
回答(3 个)
Walter Roberson
2021-11-6
I see you are using R2019b. In your release, tiledlayout was introduced; people have been happier with that for adjusting spacing.
0 个评论
Chris
2021-11-6
编辑:Chris
2021-11-6
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)
0 个评论
Star Strider
2021-11-6
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');
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 个评论
Guilherme de Melo
2024-2-9
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!
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Subplots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!