When you create your three axes (titled A, B, and C) they appear from right to left across the figure and in reverse order (C, B, A) in the handle array allax. Therefore they appear in allax in right-to-left order. Your function assumes this when adjusting the widths of these axes. You wrote:
[~,B]= min(X);
set(allax(B),'Position',[Pos{B,1}(1), Pos{B,1}(2), NW, Pos{B,1}(4)]);
for i=1:num-1
set(allax(i),'Position',[Pos{i,1}(1)-(num-i)*(Pos{i,1}(3)-NW), Pos{i,1}(2), NW, Pos{i,1}(4)]);
end
which works before the axes order is changed. But when you reorder the axes on the figure, your expression for the position of each axes no longer behaves properly.
The good news: the fix is easy! You can get the order by sorting the x coordinates of the axes positions and use that to put them in the expected order in the for loop. Try replacing the lines above with:
[~, order] = sort(X);
for i = 1:num
pos = Pos{order(i)};
pos(1) = pos(1) - (i-1) * (pos(3) - NW);
pos(3) = NW;
set(allax(order(i)), 'Position', pos);
end
Best Answer