Bring axes to front without redrawing the figure?
Asked Answered
D

2

5

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?

Depersonalize answered 6/8, 2014 at 10:13 Comment(0)
S
4

Maybe uistack could be a solution.

Try

uistack(hAxL, 'top')
Sonar answered 6/8, 2014 at 10:18 Comment(1)
works like a charm! I was no aware of uistack. This essentially halved my plotting time :-) Thank you very much!Depersonalize
E
5

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

set(hAxL ,'Layer', 'Top')
Eada answered 17/11, 2014 at 1:31 Comment(2)
uistack(hAxL, 'top') did not work for me on MATLAB R2016b, but set(hAxL ,'Layer', 'Top') worked really well!Ussery
Or set(gca, 'Layer', 'Top'); +1.Harmonious
S
4

Maybe uistack could be a solution.

Try

uistack(hAxL, 'top')
Sonar answered 6/8, 2014 at 10:18 Comment(1)
works like a charm! I was no aware of uistack. This essentially halved my plotting time :-) Thank you very much!Depersonalize

© 2022 - 2024 — McMap. All rights reserved.