2016-10-01 11 views
2

我有一个数字,如下所示,每种颜色指示第三个变量的值。我试图用相应的颜色和值创建colorbar。用于此目的的第一I get轴的'Children'Color如下:`Children`通常是颠倒的顺序吗? Matlab

curves = get(gca, 'Children'); 
mycolorset = cat(1, curves(:).Color); 

然后我意识到,颜色的顺序(相同Children的顺序)进行比较绘制的顺序颠倒。因此,我不得不申请flipud的颜色,使正确的色彩表:

set(gcf, 'Colormap', flipud(mycolorset)); 

有趣的事实是,情节浏览器显示正确的顺序曲线。

现在我想知道,这是Matlab中所有Children的通用功能,以反转?你知道一个这个变得有用的案例吗?

enter image description here

回答

2

axesChildren是有序的,使得接近一开始孩子们都接近儿童的名单(如果SortMethod is set to 'childorder',或者如果你只有一个二维图)结束时显示对儿童的顶部。

如果你动态地添加多个2D绘图到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) 

enter image description here

如果你想改变它的情节显示在其之上,你可以修改Children的顺序,或者你可以只使用得心应手uistack命令来为你做这个。

set(gca, 'Children', flipud(get(gca, 'Children'))) % Or uistack(plot1, 'top') 
get(gca, 'Children') 

% 2x1 Line array: 
% 
% Line (plot1) 
% Line (plot2) 

enter image description here

这种堆叠行为并不仅仅限于情节axes对象。您可以更改大多数UI元素(包括uipanels,figures等)上的Children排序,以确定元素的视觉堆叠。