How to change the order of lines in a Matlab figure?

Tobias Kienzler picture Tobias Kienzler · Oct 6, 2011 · Viewed 53.6k times · Source

Given a plot of three curves in a .fig file I'd like to add another plot (with hold all and plot), but put it behind one of the already existing curves (i.e. make sure the last original curve stays the foreground one). Can this be achieved without having to extract the plot data and re-plotting?

Answer

Jonas picture Jonas · Oct 6, 2011

If you know the handle of line you want on top (e.g. because you called h = plot(...), you can use uistack

uistack(h,'top')

Alternatively, you can manipulate the order of children of your current axes directly. The following puts the last-most curve on top.

chH = get(gca,'Children')
set(gca,'Children',[chH(end);chH(1:end-1)])