2

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 this image: MATLAB pic

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?

Jason D.
  • 31
  • 2
  • 2
    This is caused by the `axis equal` call, which will scale the width and height of the axis. The x and y limits for the third axes has a different ratio than the other 2. – rinkert Nov 15 '19 at 23:10
  • 1
    Remove `axis equal`. You specify all axes to go from 0 to 1 vertically (occupy full window). They are made shorter by MATLAB because of the `axis equal` and the hard-coded axes limits. You will have to set the vertical offset to a number larger than 0 to see the tick labels. – Cris Luengo Nov 15 '19 at 23:10
  • Interesting, thank you both. If I need to keep the axis equal, is there a way to programmatically calculate what the vertical positioning should be to get vertical alignment? – Jason D. Nov 15 '19 at 23:15

0 Answers0