MATLAB Answers

Vertically align bottom edge of subplots

6 views (last 30 days)
Jason Duvall
Jason Duvall on 15 Nov 2019
Answered: Abhisek Pradhan on 19 Nov 2019
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:
pic.jpg
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 Comments

Sign in to comment.

Answers (1)

Abhisek Pradhan
Abhisek Pradhan on 19 Nov 2019
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 Comments

Sign in to comment.


Translated by