组合图形时更改线条颜色

时间:2016-09-21 11:23:02

标签: matlab

我将两个图表/图表合并为一个:

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

是否可以修改(更改)图2中存在的线条颜色?该图有3条不同颜色的线条。

1 个答案:

答案 0 :(得分: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