matlab 在另一个数据系列下方绘制一个数据系列
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/207485/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Plot a data series beneath another one
提问by Will Robertson
When you plot things in Matlab, the most recently plotted data series is placed on top of whatever's already there. For example:
当您在 Matlab 中绘制事物时,最近绘制的数据系列被放置在已经存在的任何内容之上。例如:
figure; hold on
plot(sin(linspace(0,pi)),'linewidth',4,'color',[0 0 1])
plot(cos(linspace(0,pi)),'linewidth',4,'color',[1 0 0])
Here, the red line is shown on top of the blue line (where they intersect). Is there any way to set "how deep" a line is drawn, so that you can plot things beneathwhat's already there?
在这里,红线显示在蓝线(它们相交的地方)的顶部。有什么方法可以设置一条线的“深度”,以便您可以在已有的东西下方绘制东西?
回答by b3.
Use the uistackcommand. For example:
使用uistack命令。例如:
h1 = plot(1:10, 'b');
hold on;
h2 = plot(1:10, 'r');
will plot two lines with the red line plotted on top of the blue line. If you then do:
将绘制两条线,红线绘制在蓝线的顶部。如果你这样做:
uistack(h1);
the blue line will be brought to the front.
蓝线将被带到前面。
回答by b3.
You can also accomplish this by setting the order of the children vector of the current axes. If you do the following:
您还可以通过设置当前轴的子向量的顺序来完成此操作。如果您执行以下操作:
figure; hold on
h1 = plot(sin(linspace(0,pi)),'linewidth',4,'color',[0 0 1]);
h2 = plot(cos(linspace(0,pi)),'linewidth',4,'color',[1 0 0]);
h = get(gca, 'Children');
you will see that h is a vector that contains h1 and h2. The graphical stacking order is represented by the order of the handles in h. In this example, to reverse the stacking order you could do:
你会看到 h 是一个包含 h1 和 h2 的向量。图形堆叠顺序由 h 中的句柄顺序表示。在此示例中,要反转堆叠顺序,您可以执行以下操作:
h = flipud(h);
set(gca, 'Children', h);

