Vertically align bottom edge of subplots
4 ビュー (過去 30 日間)
古いコメントを表示
The following code
fig = figure;
alist = [-0.1 1 4];
cp = 0;
for counter = 1:3
a = alist(counter);
fp = [(1+sqrt(1+4*a))/(-2*a) (1-sqrt(1+4*a))/(-2*a)];
fpmin = (abs(fp(1)-cp) < abs(fp(2)-cp))*fp(1) + (abs(fp(1)-cp) >= abs(fp(2)-cp))*fp(2);
fpmax = (abs(fp(1)-cp) >= abs(fp(2)-cp))*fp(1) + (abs(fp(1)-cp) < abs(fp(2)-cp))*fp(2);
ax = axes('Position',[.1+(counter-1)*0.3 0 0.25 1]);
axis equal;
hold on;
fplot(@(x) 1-a*x.^2,'color','k');
fplot(@(x) x,'--','color','b');
plot([fpmax -fpmax -fpmax fpmax fpmax],[fpmax fpmax -fpmax -fpmax fpmax],'color','r');
padding = .4*abs(fpmax);
axis([-abs(fpmax)-padding abs(fpmax)+padding -abs(fpmax)-padding max(abs(fpmax),1)+padding]);
end
produces the following image:
The issue is that MATLAB didn't place the third image correctly. The line of code
ax = axes('Position',[.1+(counter-1)*0.3 0 0.25 1]);
supposedly tells MATLAB to position the bottom left corner of each new axis at a height of 0. But this isn't happening in the third image. I also tried using subplots but that produces the same behavior as seen above. How do I vertically align the three axes along their bottoms, if the 'Position' thing I tried doesn't work?
0 件のコメント
回答 (1 件)
Abhisek Pradhan
2019 年 11 月 19 日
I was able to reproduce the problem using your code.
ax = axes('Position',[.1+(counter-1)*0.3 0 0.25 1]);
the above line of code is working as expected. But
axis([-abs(fpmax)-padding abs(fpmax)+padding -abs(fpmax)-padding max(abs(fpmax),1)+padding]);
is causing unexpected behaviour, because of it's arguments being dependent on various values like fpmax, padding and alist.
3rd value of 'alist' being large as compared to 1st and 2nd we can see the difference. While looping 3rd loop can be handled separately to get the expected result.
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Subplots についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!