Change Figure Bottom Margin

5 ビュー (過去 30 日間)
Peter
Peter 2013 年 2 月 19 日
編集済み: Gautam 2024 年 8 月 29 日
Dear all,
I would like to generate a 2x3 subplot and display the legend below the figure:
%
figure
for i = 1:6
h_subplot = subplot(2,3,i);
plot(randn(10,2))
if i==5
h_legend = legend({'Data 1', 'Data 2'});
sp=get(h_subplot,'position');
set(h_legend,'position',[sp(1),sp(2)-.15,sp(3),.1]);
end
end
How can I extend the bottom margin, without resizing the subplots, such that the entire legend is shown?
Thanks, Peter

回答 (1 件)

Gautam
Gautam 2024 年 8 月 29 日
編集済み: Gautam 2024 年 8 月 29 日
Hello Peter,
One easy way to extend the bottom margin of the figure without resizing the subplots is by adding another row to the subplots and setting the “Visibility” property of its axis to “off”
set(subplot(3,3,[7 8 9]), "Visible", "off");
The code below follows this to generate the corresponding output:
f=figure;
for i = 1:6
h_subplot = subplot(3,3,i);
plot(randn(10,2))
if i==5
h_legend = legend({'Data 1', 'Data 2'});
sp=get(h_subplot,'position');
set(h_legend,'position',[sp(1),sp(2)-.15,sp(3),.1]);
end
end
set(subplot(3,3,[7 8 9]), "Visible", "off");
Hope this helps

カテゴリ

Help Center および File ExchangeSubplots についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by