绘图后更改线条颜色
Change line colors after plotting
在 this 之后,我绘制了一个信号矩阵 t
(m x 1)和 x
(m x n):
plot(t,x);
之后,我希望在颜色图矩阵 c
(n x 3)上应用颜色方案。怎么做?
编辑
简单地说,忽略 most - 如果不是全部 - 性能礼仪,通过 for
调用你可以设置颜色 while 构建一个情节,绘制循环内的每一列,以及 setting/applying 颜色图 'on the fly',正如指出的 post 所建议的那样,但这 不是 问题:
for i=1:n
plot(t(:,1),x(:,i),'Color',c(i,:));
hold on;
end
这是伪代码,如果您没有定义 t
、x
和 c
,将不会 运行 .
数据,以及此处显示的代码,已煮熟,为您准备就绪:
load spectra.mat;
x=NIR'; m=size(x,1);n=size(x,2);
t=900+2*(1:m)'; %Don't question this :)...
c=winter(n);
for i=1:n
plot(t(:,1),x(:,i),'Color',c(i,:));
hold on;
end
title('Near Infrarred Spectra for Gasoline Samples');
xlabel('Wavelength [nm]');
ylabel('Infrarred Spectral Magnitude [lm^2/nm]');
或没有 for
,更好:
load spectra.mat;
x=NIR'; m=size(x,1);n=size(x,2);
t=900+2*(1:m)'; %Don't question this :)...
c=winter(n);
set(0,'DefaultAxesColorOrder',c);
plot(t,x);
title('Near Infrarred Spectra for Gasoline Samples');
xlabel('Wavelength [nm]');
ylabel('Infrarred Spectral Magnitude [lm^2/nm]');
.
不幸的是,他们所有人都先于密谋。再也没有...
我找到了 this 函数 (CMAPLINE):
plot(t,x,':o');
cmapline('colormap',c);
这解决了问题。感谢小伙伴们的评论。
hypfco.
在 this 之后,我绘制了一个信号矩阵 t
(m x 1)和 x
(m x n):
plot(t,x);
之后,我希望在颜色图矩阵 c
(n x 3)上应用颜色方案。怎么做?
编辑
简单地说,忽略 most - 如果不是全部 - 性能礼仪,通过 for
调用你可以设置颜色 while 构建一个情节,绘制循环内的每一列,以及 setting/applying 颜色图 'on the fly',正如指出的 post 所建议的那样,但这 不是 问题:
for i=1:n
plot(t(:,1),x(:,i),'Color',c(i,:));
hold on;
end
这是伪代码,如果您没有定义 t
、x
和 c
,将不会 运行 .
数据,以及此处显示的代码,已煮熟,为您准备就绪:
load spectra.mat;
x=NIR'; m=size(x,1);n=size(x,2);
t=900+2*(1:m)'; %Don't question this :)...
c=winter(n);
for i=1:n
plot(t(:,1),x(:,i),'Color',c(i,:));
hold on;
end
title('Near Infrarred Spectra for Gasoline Samples');
xlabel('Wavelength [nm]');
ylabel('Infrarred Spectral Magnitude [lm^2/nm]');
或没有 for
,更好:
load spectra.mat;
x=NIR'; m=size(x,1);n=size(x,2);
t=900+2*(1:m)'; %Don't question this :)...
c=winter(n);
set(0,'DefaultAxesColorOrder',c);
plot(t,x);
title('Near Infrarred Spectra for Gasoline Samples');
xlabel('Wavelength [nm]');
ylabel('Infrarred Spectral Magnitude [lm^2/nm]');
不幸的是,他们所有人都先于密谋。再也没有...
我找到了 this 函数 (CMAPLINE):
plot(t,x,':o');
cmapline('colormap',c);
这解决了问题。感谢小伙伴们的评论。
hypfco.