`Children`一般都是顺序颠倒的吗?软件
Are `Children` generally in the reversed order? Matlab
我有一个如图所示的图形,每种颜色表示第三个变量的值。我试图用相应的颜色和值创建一个 colorbar
。为此我首先get
'Children'
的Color
轴如下:
curves = get(gca, 'Children');
mycolorset = cat(1, curves(:).Color);
然后我意识到颜色的顺序(与Children
的顺序相同)与绘图的顺序相反。所以我必须将 flipud
应用于颜色以制作正确的颜色图:
set(gcf, 'Colormap', flipud(mycolorset));
有趣的是 Plot Browser 以正确的顺序显示曲线。
现在我想知道,这是不是Matlab中所有Children
的一个普遍特征要反了?你知道这个有用的案例吗?
axes
的 Children
排序后,靠近开头的子项显示在靠近子项列表末尾的子项之上(如果 SortMethod
is set to 'childorder'
或如果你只有一个二维图)。
如果您动态地向 axes
添加多个二维绘图,MATLAB 的默认行为是将新绘图对象放置在旧绘图对象之上,因此需要将它们附加到Children
列表。
figure;
hold on
plot1 = plot(1:10, 'LineWidth', 10, 'DisplayName', 'plot1');
plot2 = plot(10:-1:1, 'LineWidth', 10, 'DisplayName', 'plot2');
legend([plot1, plot2])
get(gca, 'Children')
% 2x1 Line array:
%
% Line (plot2)
% Line (plot1)
如果你想改变哪个图显示在哪个图之上,你可以修改 Children
的顺序,或者你可以只使用方便的 uistack
命令来为你做这件事。
set(gca, 'Children', flipud(get(gca, 'Children'))) % Or uistack(plot1, 'top')
get(gca, 'Children')
% 2x1 Line array:
%
% Line (plot1)
% Line (plot2)
这种堆叠行为不仅限于 axes
中的绘图对象。您可以更改大多数 UI 元素(包括 uipanels
、figures
等)的 Children
顺序以确定元素的视觉堆叠。
我有一个如图所示的图形,每种颜色表示第三个变量的值。我试图用相应的颜色和值创建一个 colorbar
。为此我首先get
'Children'
的Color
轴如下:
curves = get(gca, 'Children');
mycolorset = cat(1, curves(:).Color);
然后我意识到颜色的顺序(与Children
的顺序相同)与绘图的顺序相反。所以我必须将 flipud
应用于颜色以制作正确的颜色图:
set(gcf, 'Colormap', flipud(mycolorset));
有趣的是 Plot Browser 以正确的顺序显示曲线。
现在我想知道,这是不是Matlab中所有Children
的一个普遍特征要反了?你知道这个有用的案例吗?
axes
的 Children
排序后,靠近开头的子项显示在靠近子项列表末尾的子项之上(如果 SortMethod
is set to 'childorder'
或如果你只有一个二维图)。
如果您动态地向 axes
添加多个二维绘图,MATLAB 的默认行为是将新绘图对象放置在旧绘图对象之上,因此需要将它们附加到Children
列表。
figure;
hold on
plot1 = plot(1:10, 'LineWidth', 10, 'DisplayName', 'plot1');
plot2 = plot(10:-1:1, 'LineWidth', 10, 'DisplayName', 'plot2');
legend([plot1, plot2])
get(gca, 'Children')
% 2x1 Line array:
%
% Line (plot2)
% Line (plot1)
如果你想改变哪个图显示在哪个图之上,你可以修改 Children
的顺序,或者你可以只使用方便的 uistack
命令来为你做这件事。
set(gca, 'Children', flipud(get(gca, 'Children'))) % Or uistack(plot1, 'top')
get(gca, 'Children')
% 2x1 Line array:
%
% Line (plot1)
% Line (plot2)
这种堆叠行为不仅限于 axes
中的绘图对象。您可以更改大多数 UI 元素(包括 uipanels
、figures
等)的 Children
顺序以确定元素的视觉堆叠。