Plot multiple lines with gradient gray hue

29 ビュー (過去 30 日間)
ep
ep 2014 年 11 月 25 日
回答済み: Simon Dengler 2022 年 11 月 29 日
I have created a 10-line plot and I want each line to have a gray hue, gradient from dark for the first line to light to light for the last. I know that the rgb colors I need to use are the following: [1 1 1], [0.9 0.9 0.9], [0.8 0.8 0.8], ..., [0.2 0.2 0.2] and [0.1 0.1 0.1] but when I use them in the plot command it fails to work, all lines appear to have the same color. My plot command is the following:
plot(x1,y1,x2,y2,x3,y3,x4,y4,x5,y5,x6,y6,x7,y7,x8,y8,x9,y9,x10,y10,'Color',[1 1 1],'Color',[0.9 0.9 0.9],'Color',[0.8 0.8 0.8],'Color',[0.7 0.7 0.7],'Color',[0.6 0.6 0.6],'Color',[0.5 0.5 0.5],'Color',[0.4 0.4 0.4],'Color',[0.3 0.3 0.3],'Color',[0.2 0.2 0.2],'Color',[0.1 0.1 0.1])

採用された回答

Stephen23
Stephen23 2014 年 11 月 25 日
This can be done quite easily in one plot command without a loop, using a matrix as the input (as the plot documentation explains), and the 'ColorOrder' axes-property:
N = 10;
C = repmat(linspace(1,0.1,N).',1,3);
axes('ColorOrder',C,'NextPlot','replacechildren')
X = linspace(0,pi*3,1000);
Y = bsxfun(@(x,n)n*sin(x+2*n*pi/N), X.', 1:N);
plot(X,Y, 'linewidth',4)
(untested, but I only slightly adapted it from one of the plot examples here: http://www.mathworks.com/matlabcentral/fileexchange/45208 )

その他の回答 (3 件)

Mischa Kim
Mischa Kim 2014 年 11 月 25 日
編集済み: Mischa Kim 2014 年 11 月 25 日
Alverto, you could use something like
my_col = repmat(linspace(0,1,10)',1,3); % create your own gray colors color map
t = 0:0.1:pi;
a = 1:length(my_col(:,1));
y = a'*sin(t);
hold all
for ii = 1:numel(a) % show 10 plots with color map
plot(y(ii,:),'color',my_col(ii,:))
leg{ii} = strcat('data',num2str(ii));
end
legend(leg)
To see how the color map looks like simply remove the semi colon at the end of the first command.
  1 件のコメント
ep
ep 2014 年 11 月 25 日
編集済み: ep 2014 年 11 月 25 日
Thanks. Is it possible to do the same thing without a loop in only one plot command?

サインインしてコメントする。


homa rashidisabet
homa rashidisabet 2018 年 5 月 16 日
Thank yoooouuuuu

Simon Dengler
Simon Dengler 2022 年 11 月 29 日
I'm using
colororder([jet(44)])
for similar functionality

カテゴリ

Help Center および File ExchangeOrange についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by