2016-09-21 76 views
0

,當我將兩個圖形/圖到一個這樣的:更改線的顏色組合圖表

fig1 = open('fig1.fig') 
fig2 = open('fig2.fig') 

ax1 = get(fig1, 'Children'); 
ax2 = get(fig2, 'Children'); 

for i = 1 : numel(ax2) 
    ax2Name = get(ax2(i), 'Children'); 
    copyobj(ax2Name, ax1(i)); 
end 

是否有可能修改(其他城市)中存在的fig2線的顏色?情節有不同顏色的3條線。

回答

1
x = 1:0.1:5; 
y1 = x.^2; 
y2 = sqrt(x); 
y3 = sin(x); 

figure; 
plot(x, y1, x, y2); 
fig1 = gcf; 
ax1 = fig1.Children; % same as get(fig1, 'Children') 
line1 = ax1.Children; 

figure; 
plot(x, y3); 
fig2 = gcf; 
ax2 = fig2.Children 

for l = line1 % iterate over Line array 
    copyobj(l, ax2) % copy each Line object from ax1 to ax2 
end 

disp(ax2.Children) 
line2 = ax2.Children; 
line2(1).Color = [1 0 0]; % first line (^2): red 
line2(2).Color = [0 1 0]; % second line (sqrt): green 
line2(3).Color = [0 0 1]; % third line (sine): blue 
+0

如果一個情節有3行不同的顏色,是否有可能只改變一個特定的行? –

+0

我不知道如何訂購。除此之外,'c(1)':第一行,'c(2)':第二行,'c(3)':第三行。 'set(c(3),'Color',[0 1 0])'將第三個設置爲綠色。 – Jeon

+0

我有點不確定如何將這與我在帖子中提供的示例結合起來。有可能適合我的例子嗎? –