Figure size for multiple subplots is not even
Show older comments
I would like to have two subplots with a legend under them. Unfortunately the upper plot is smaller the the lower one. My example is.
clear all;
close all;
%%Generate data
n=6;
f = 200;
x(:,1) = linspace(0,1,101);
for i = 1:n;
y1(:,i) = linspace(-100,i*10,101);
y2(:,i) = linspace(-4,i,101);
f=f*2;
list{i} = [num2str(f) ' Hz'];
end
%
%%Plot data
ax1 = subplot(211);
plot(x,y1);
axis([0 1 -100 20]);
LY1 = get(ax1,'YLim');
Bildhoehe1 = get(gcf);
NumTicksY1 = abs((LY1(1)-LY1(2))/20);
set(ax1,'YTick',linspace(LY1(1),LY1(2),NumTicksY1+1));
n1 = get(gcf);
%
ax2 = subplot(212);
plot(x,y2);
axis([0 1 -5 1]);
LY2 = get(ax2,'YLim');
Bildhoehe2 = get(ax2, 'position');
NumTicksY2 = abs((LY2(1)-LY2(2))/1);
set(ax2,'YTick', linspace(LY2(1),LY2(2),NumTicksY2+1));
n2 = get(gcf);
%
%%Change ylabel for subplot
hLabel1 = ylabel(ax1,'Amplitude in dB');
hLabel2 = ylabel(ax2,'Phase in \pi');
pos1 = get(hLabel1, 'Position');
pos2 = get(hLabel2, 'Position');
newX = min(pos1(1), pos2(1));
pos1(1) = newX;
pos2(1) = newX;
set(hLabel1, 'Position', pos1);
set(hLabel2, 'Position', pos2);
%
%%define xlabel
xlabel('Abstand in cm');
%
%%Define Legend
AX = legend(list,'Location','southoutside', 'orientation', 'horizontal');
AX.FontName = 'Helvetica';
Any suggestions? How do I know, what fonts are installed? Best regards, Henrik
Accepted Answer
More Answers (0)
Categories
Find more on Subplots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!