2016-10-01 83 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排序,以確定元素的視覺堆疊。