Plotting many plots on same figure with unique colors

조회 수: 27 (최근 30일)
abc
abc 2014년 3월 2일
댓글: Lars Abrahamsson 2020년 9월 2일
Hi,
I am adding plots to a figure in my for loop as given below. I used 'Color' setting to define the colors. However there are only 7 options as per the ColorSpec given in MATLAB help. I may need to plot hundreds of plots in the same graph. How can I generate those many unique colors and then ask MATLAB to plot different lines in those colors?
colorstring = 'kbgrymckbg';
for buscnt=1:Nbus-1
for bw_combination=1:Ncomb
if bw_combination==1
figure();
end
plot(x_plot,y_plot, 'Color', colorstring(bw_combination));
hold on
end
end

채택된 답변

abc
abc 2014년 3월 2일
  댓글 수: 2
Lars Abrahamsson
Lars Abrahamsson 2020년 9월 2일
At least the former one needs a toolbox unfortunately ...
Lars Abrahamsson
Lars Abrahamsson 2020년 9월 2일
The latter one works fine - thanks!

댓글을 달려면 로그인하십시오.

추가 답변 (2개)

Image Analyst
Image Analyst 2014년 3월 2일
You can simply use any 3 element array of numbers between 0 and 1 to define whatever color you want. They don't have to be any of the specially named colors that use specific letters, for example
plot(x,y,'Color', [2., 3., .7]); % Use whatever numbers you want.
  댓글 수: 2
abc
abc 2014년 3월 2일
Thank you for your answer. The problem is that I need to do this within a loop and may need to plot hundreds of plots on the same figure. This may get a bit tedious. The two files posted earlier completely suit the purpose.
Lars Abrahamsson
Lars Abrahamsson 2020년 9월 2일
Moreover, it is important to avoid for example yellow, that is far too bright for white background.

댓글을 달려면 로그인하십시오.


Saeed Bello
Saeed Bello 2017년 5월 25일
The link below gives a function to solve this problem:
https://www.mathworks.com/matlabcentral/fileexchange/42673-beautiful-and-distinguishable-line-colors-+-colormap

카테고리

Help CenterFile Exchange에서 Graphics Performance에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by