Can I have same plot colors between 2 different figures?

4 次查看(过去 30 天)
Hi,
I have 2 Figures. Each has a Axes area with 4 plots each.
When I do 'hold all' - Matlab assign colors to the plots automatically.
I want to have the two figures plot colors the same meaning - Line#1 in Axis#1 will have the same color as Line#1 in Axes#2....
Is it possible to do so without setting manually the colors to each line?
Is there a 'hold' sequence where this might work?

回答(1 个)

Azzi Abdelmalek
Azzi Abdelmalek 2013-3-4
Example
t=0:0.1:10
y11=cos(t)
y12=2*cos(t)
h1(1)=plot(t,y11)
hold on
h1(2)=plot(t,y12)
set(h1(1),'color','red')
set(h1(2),'color','green')
figure
y21=sin(t)
y22=2*sin(t)
h2(1)=plot(t,y21)
hold on
h2(2)=plot(t,y22)
set(h2(1),'color','red')
set(h2(2),'color','green')
  6 个评论
Azzi Abdelmalek
Azzi Abdelmalek 2013-3-5
编辑:Azzi Abdelmalek 2013-3-5
Then What is the problem? Just use hold all, with the order of plotting you want. The colors are givens in the order
Nimrodb
Nimrodb 2013-3-5
编辑:Nimrodb 2013-3-5
My code is as such (If you have suggesting on changing it but getting the same result - I'm happy to hear it):
hold all
%%Plotting x plots:
for i = 1:size(Data(:,1),1)
h.Plots(i,1) = plot(Data(i,:),(TxArray+TxArray*0.1*i));
end
%%Assigning the x plots to to Axes(1): {Matlab sets plots color automatically}
for i = 1:size(Data(:,1),1)
if ~isempty(h.Plots(i))
set(h.Plots(i),...
'Parent',h.Axes(1),...
'LineWidth',[3.0],...
'DisplayName',STAName);
end
end
h.Legend(1) = legend(h.Axes(1),'show');
%%Plotting same number of plots as in Axes(1) but a bit differently:
for i = 1:size(Data(:,1),1)
h.Plots(i,2) = plot(Data(i,:),(TxArray/4+(i-1)/3));
end
%%Assigning the x plots to Axes(2):
for i = 1:size(Data(:,1),1)
if ~isempty(h.Plots(i))
set(h.Plots(i,2),...
'Parent',h.Axes(2),...
'LineWidth',[3.0],...
'color',get(h.Plots(i,1),'color'),...%%This is my current solution
'DisplayName',STAName);
end
end

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Annotations 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by