Bring axes to front without redrawing the figure?

user986990 picture user986990 · Aug 6, 2014 · Viewed 10.2k times · Source

Is there a way in Matlab to bring an axes to front without having Matlab perform a redraw (drawnow) implicitly?

Background to my question: I am preparing a large figure with several subplots. In some of them I have 2 axes superposed, because I want to see the same data on 2 different y-scales. After playing around with axes settings, I finally got the figure to look like I expected.

But: I need to bring one of the axes to front (in my case, the left axes hAxL). So I have this line in my code: axes(hAxL); This works, but, it seems that Matlab not only brings the axes to front, but also redraws the figure.

That's a pity because I am preparing the entire figure with 'visible','off' to accelerate it. The implicit drawnow blows my idea and makes the figure popup several times, which is annoying and takes the code longer to execute...

I have already tried this: set(gcf ,'CurrentAxes',hAxL), but it only makes hAxL the current axes and does not bring it to front. Any idea on how to solve this?

Answer

Seth_P picture Seth_P · Nov 17, 2014

This is also a pretty simple solution that should work for that situation.

set(hAxL ,'Layer', 'Top')