如何更改 Matlab 图中线条的顺序?图中、线条、顺序、如何更改

2023-09-07 02:10:37 作者:与世无争的帅哥

鉴于 .fig 文件中的三条曲线图,我想添加另一个图(使用 hold allplot),但把它放在 在已经存在的曲线之一的后面(即确保最后一条原始曲线保持在前景曲线).无需提取绘图数据并重新绘图就可以实现这一点吗?

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?

推荐答案

如果你知道你想要在顶部的线的句柄(例如,因为你调用了 h = plot(...),你可以使用 uistack

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)])