Avoid using figure() without any arguments. Create axes explicitly and parent them against the figure. Parent all plotting elements explicitly against the axes (or figure, as appropriate.) Do not use figure(ID) to switch attention to that figure: if you need to switch attention then set(0,'CurrentFigure',ID). But with parenting explicitly the circumstances under which you will need to do that will be reduced.