How to Change the Staking Order of Lines from Back-to-Front to Front-to-Back?

293 ビュー (過去 30 日間)
It seems that the order of staking lines in a graph is back-to-front, so blue line will be behind red line.
hor_line = [1,1,1];
ver_line = [0,1,2];
plot([0 1 2],hor_line ,[1,1,1],ver_line, 'LineWidth', 8);
Is there any way to change the default staking order of lines from back-to-front to front-to-back? (so, by the same code, I will get the following)
hor_line = [1,1,1];
ver_line = [0,1,2];
plot([0 1 2],hor_line ,[1,1,1],ver_line, 'LineWidth', 8);

採用された回答

Walter Roberson
Walter Roberson 2018 年 9 月 23 日
"It seems that the order of staking lines in a graph is back-to-front, so blue line will be behind red line."
There are two choices of visibility order of graphics objects in R2015b and later. They are described in the blog https://blogs.mathworks.com/graphics/2014/11/04/sortmethod/
Those are the only choices. In particular, there is no way of configuring to say that the first line specified in one plot() call should be on top of the second, third, etc., line in the same plot() call. plot() is for creating 2D lines, and axes with only 2D lines default to childorder, and child order for a series of lines drawn in the same plot call is always that the later lines draw over top of the first, same as if you had done a series of plot() calls of individual lines. This is not a default you can change.
You can change the stacking order after you draw everything, such as
set(gca, 'Children', flipud(get(gca, 'Children')) )
  2 件のコメント
Walter Roberson
Walter Roberson 2018 年 9 月 24 日
When you do not pass a list of graphics handles into legend() then legend() respects ChildOrder -- so the first legend is associated with the last entry on ChildOrder, the second legend is associated with the second last entry in ChildOrder, and so on bottom to top in ChildOrder. Bottom to top because the bottom entry is the first entry that was plotted unless the ChildOrder was changed.
You can change this by passing a list of graphics handles in to legend.
h = plot(1:10,2:11,'r*-',1:10, (11:-1:2), 'g^--');
legend(flipud(h), 'green', 'red')

サインインしてコメントする。

その他の回答 (0 件)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by