# How to equalize width & aspect between axes?

15 views (last 30 days)
Evan on 6 Nov 2016
Commented: Evan on 7 Nov 2016
I have two plots stacked vertically. In one, the x and y data have the same units, so I'm using "axes equal." In the second, x & y do not have the same units, but the x data from both plots are the same. Is there some way to equalize the size and aspect of the x axes across the two plots? I assumed that I could just set the x values in the 'Position' property to be equal, but apparently this is not how "axes equal" functions.
I found that the following procedure seems to work:
~make plot 1~
%Make plot 1
set(gca,'DataAspectRatio',[1 1 1])
ar = get(gca,'PlotBoxAspectRatio')
%Make plot 2
set(gca,'PlotBoxAspectRatio',ar)
Does anyone know a more proper way to do this?

Image Analyst on 6 Nov 2016
You can set the size of each axes. You did not do that. Moreover, you didn't even change the current axes between your calls to set() so the two sets's will apply to the same axes. Try this:
handles.axes1.Position = [x1,y1,width1, height1];
handles.axes2.Position = [x2,y2,width2, height2];
You can figure out the 2 parameters based on the 1 parameters if you want. You might also be interested in the "axis equal" and/or "axis square" commands.
Evan on 7 Nov 2016
I did use "axis equal." Also, I did try the Position property, but that doesn't work because axis equal has no effect on the position property: you can see for yourself with this code:
x = linspace(1,100,100);
y1 = linspace(1,150,100);
y2 = randn(1,100);
figure;
h1 = subplot(2,1,1);
plot(x,y1)
pos1_original = h1.Position;
axis equal
set(h1,'XLim',[0 100], ...
'YLim',[0 150])
pos1 = h1.Position;
h2 = subplot(2,1,2);
plot(x,y2)
pos2 = h2.Position;
set(h2,'XLim',[0 100], ...
'Position',[pos1(1) pos2(2) pos1(3) pos2(4)])