Change Figure Bottom Margin

5 views (last 30 days)
Peter
Peter on 19 Feb 2013
Edited: Gautam on 29 Aug 2024
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

Answers (1)

Gautam
Gautam on 29 Aug 2024
Edited: Gautam on 29 Aug 2024
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

Products

Community Treasure Hunt

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

Start Hunting!