MATLAB: Does changing ydir to ‘reverse’ change xdir and axis locations, but not ydir

ydir

I am updating an old GUI created in 2004 (by someone else) to be usable again, and one of the main problems was that elements of the GUI overlapped: There are two plots and a set of uicontrol elements. I moved the positions of the uicontrols, but there is still overlap with the plots.
The left plot is Axes2, the right plot is Axes1, but the left one is used first.
The y-axis should be reversed, the x-axis normal, and the axis locations should be "left" and "bottom". The right plot is meant to have no yticklabels.
The problem, as you can probably see in the image, is that setting the Ydir-property to 'reverse' does not change the direction of the y-axis, but what happens is that Xdir is set to 'reverse' and the axis locations are changed to 'right' and 'top', and not even explicitly setting them to 'left' and 'bottom' moves them to the right place. The axis labels are also consequently in the wrong place. This is the code in the program that plots the data:
if true
% code

%%GUI laden
inversion_gui_edit; % load GUI PM
hold on
box on
patch([-1e-3 1e-3 1e-3 -1e-3 -1e-3],...
[0 0 zmax0 zmax0 0],...
[0.7 0.7 0.7],...
'EdgeColor','none');
hold on;
plot(0*ones(2,1),[0 zmess0(N0)],'k-',... % make vertical line at 0 PM
TMess,zmess0,'k:',... % plot Temperatures
TMess,zmess0,'ko'); % mark Temperatures
if (max(abs(TMess))<.1||max(abs(TMess))==.1); % || means OR
axis([-.1 .1 0 zmax0])
end;
if max(abs(TMess))>.1;
axis([-max(abs(TMess)) max(abs(TMess)) 0 zmax0])
end;
grid on;
title('T [K] with BTV and q/k=0');
ylabel('z [m]');
ax = gca
ax.YDir = 'reverse';
ax.YAxisLocation = 'left';
ax.XAxisLocation = 'bottom';
for bar0=1:N0;
barx0=[TMess(bar0)-1e-3 TMess(bar0)+1e-3];
bary0=[zmess0(bar0) zmess0(bar0)];
plot(barx0,bary0,'k-','LineWidth',2);
end;
achse=axis;
achse=achse(2);
xlabel(['Station ',FILENAME(5:6),' Pen ',FILENAME(8:9)]); %PM
H11=findobj('Tag','Axes1');
H12=findobj('Tag','Axes2');
plot(0*ones(2,1),[0 zmess0(N0)],'k-',...
kMess,zmess0,'k:',...
kMess,zmess0,'ko',...
'Parent',H11);
set(H11,'ydir','reverse');
set(H11,'YTickLabel',[]);
set(H11,'XGrid','on');
set(H11,'YGrid','on');
set(H11,'XLim',[-.5 .5]);
if max(abs(kMess))>.5;
set(H11,'XLim',[-max(abs(kMess)) max(abs(kMess))]);
end;
set(H11,'YLim',[0 zmax0]);
end
For the sake of completeness, this is how the axes are set up for the gui:
if true
% code
h1 = axes('Parent',h0, ...
'Units','pixels', ...
'CameraUpVector',[0 1 0], ...
'CameraUpVectorMode','manual', ...
'Color',[1 1 1], ...
'ColorOrder',mat8, ...
'Position',[268+5 84 148 355], ...
'Tag','Axes1', ...
'XColor',[0 0 0], ...
'YColor',[0 0 0], ...
'ZColor',[0 0 0]);
h2 = text('Parent',h1, ...
'Color',[0 0 0], ...
'HandleVisibility','off', ...
'HorizontalAlignment','center', ...
'Position',[0.4965986394557824 -0.07909604519774005 9.160254037844386], ...
'Tag','Axes1Text4', ...
'VerticalAlignment','cap');
set(get(h2,'Parent'),'XLabel',h2);
h2 = text('Parent',h1, ...
'Color',[0 0 0], ...
'HandleVisibility','off', ...
'HorizontalAlignment','center', ...
'Position',[-0.2380952380952381 0.4971751412429378 9.160254037844386], ...
'Rotation',90, ...
'Tag','Axes1Text3', ...
'VerticalAlignment','baseline');
set(get(h2,'Parent'),'YLabel',h2);
h2 = text('Parent',h1, ...
'Color',[0 0 0], ...
'HandleVisibility','off', ...
'HorizontalAlignment','right', ...
'Position',mat9, ...
'Tag','Axes1Text2', ...
'Visible','off');
set(get(h2,'Parent'),'ZLabel',h2);
h2 = text('Parent',h1, ...
'Color',[0 0 0], ...
'HandleVisibility','off', ...
'HorizontalAlignment','center', ...
'Position',[0.4965986394557824 1.022598870056497 9.160254037844386], ...
'Tag','Axes1Text1', ...
'VerticalAlignment','bottom');
set(get(h2,'Parent'),'Title',h2);
h1 = axes('Parent',h0, ...
'Units','pixels', ...
'CameraUpVector',[0 1 0], ...
'CameraUpVectorMode','manual', ...
'Color',[1 1 1], ...
'ColorOrder',mat10, ...
'Position',[51 84 179 355], ...
'Tag','Axes2', ...
'XColor',[0 0 0], ...
'YColor',[0 0 0], ...
'ZColor',[0 0 0]);
h2 = text('Parent',h1, ...
'Color',[0 0 0], ...
'HandleVisibility','off', ...
'HorizontalAlignment','center', ...
'Position',[0.4943820224719101 -0.07909604519774005 9.160254037844386], ...
'Tag','Axes2Text4', ...
'VerticalAlignment','cap');
set(get(h2,'Parent'),'XLabel',h2);
h2 = text('Parent',h1, ...
'Color',[0 0 0], ...
'HandleVisibility','off', ...
'HorizontalAlignment','center', ...
'Position',mat11, ...
'Rotation',90, ...
'Tag','Axes2Text3', ...
'VerticalAlignment','baseline');
set(get(h2,'Parent'),'YLabel',h2);
h2 = text('Parent',h1, ...
'Color',[0 0 0], ...
'HandleVisibility','off', ...
'HorizontalAlignment','right', ...
'Position',mat12, ...
'Tag','Axes2Text2', ...
'Visible','off');
set(get(h2,'Parent'),'ZLabel',h2);
h2 = text('Parent',h1, ...
'Color',[0 0 0], ...
'HandleVisibility','off', ...
'HorizontalAlignment','center', ...
'Position',[0.4943820224719101 1.022598870056497 9.160254037844386], ...
'Tag','Axes2Text1', ...
'VerticalAlignment','bottom');
set(get(h2,'Parent'),'Title',h2);
end
The blank gui looks like this and is fine:
I haven't got a clue why this is happening and I'd be happy for some pointers as to what I could try to fix this. Could a be an issue with the 2015b release I'm using??

Best Answer

Probably you messed up the first and the second plot. gca may give you the axes of the right plot, and then you try to reverse the invisible y-axis. I would define ax_left and ax_right referring to the left and right plot, resp., once you have created the axes, and then work on these, without using gca.
I also found out that the example works if you delete the lines
'CameraUpVector',[0 1 0], ...
'CameraUpVectorMode','manual', ...
when you create the axes. They seem to interfere with he YDir setting:
h1 = axes('Parent',h0, ...
'Units','pixels', ...
'Color',[1 1 1], ...
'Position',[268+5 84 148 355], ...
'Tag','Axes1', ...
'XColor',[0 0 0], ...
'YColor',[0 0 0], ...
'ZColor',[0 0 0]);
ax_right = h1;
h1 = axes('Parent',h0, ...
'Units','pixels', ...
'Color',[1 1 1], ...
'Position',[51 84 179 355], ...
'Tag','Axes2', ...
'XColor',[0 0 0], ...
'YColor',[0 0 0], ...
'ZColor',[0 0 0], 'YDir', 'reverse');
ax_left = h1;
ax_left.YAxisLocation = 'right';
ax_left.YDir = 'reverse';
ax_left.XTick = [];
ax_right.YTick = [];
ax_right.XLim = [-.5 .5];