Matlab provides a function called uistack for arranging UI objects in the depth direction (which objects are in front of which others, etc). There is also a function (axes) for setting the current axes. I find that when I call axes, it also automatically puts that axes object in front of all other objects (including uipanels, etc). Is there any way to avoid this?
Here is some code that illustrates my question:
figure(1)
clf
ax1 = axes();
set(ax1,'position',[.1 .1 .5 .5],'xtick',[],'ytick',[],'color','r')
ax2 = axes();
set(ax2,'position',[.3 .3 .5 .5],'xtick',[],'ytick',[],'color','b')
% blue (ax2) is on top since it was created after ax1
uistack(ax1,'top')
% red (ax1) is now on top (good)
axes(ax2)
% [do some plotting or something in ax2]
% blue (ax2) is now on top (I'd rather avoid this)
To make
h_axthe current axes in figureh_figwithout putting those axes in front, use:Why this works
From the documentation of the
axesfunction, the syntaxaxes(cax)Making
caxthe first object listed in theChildrenproperty is what causes it to be in front. This can be checked by modifying that property and seeing the effect. Also, by looking atuistack's code it is seen that what that function internally does it to rearrange the order of the figure'sChildren.Setting the figure's
CurrentAxesproperty tocaxis what causes those axes to be the current ones. This can be checked by modifying that property, plotting something and seeing in what axes the plot appears.So, setting the
CurrentAxesproperty of the figure to the desired axes achieves the desired effect without moving those axes to the front.