Plotting 20-100 line with different distinguishable colors and shades on the same figure using a for loop
조회 수: 16 (최근 30일)
이전 댓글 표시
I'm trying to plot multiple data lines point on the same figure by executing a for loop (see below) which should plot one line per iteration for 10, 20, or 100 iterations . The problem is that the default setting output only 7 colors, so there are about lines of the same color for 2-3 iterations per figure (Please see example figure attached for clarification). I researched and found that the function "distinguishable_colors" is supposed to increase the variation in the colors for a wider range, and thus fits my purpose. However, I'm having problems executing the code with that function. I'd appreciate your help to make it work. Thank you.
%.<---...some code....
PixelCountLast10(PixelCountLast10==0)=NaN;
ColMap=distinguishable_colors(20);
figure(FigLast10)
for TrialLast10=PlotInitValLast10:StartInt:LastFrameLast10;
IterationNoLast10=(TrialLast10-1)./800+1;
txtLast10=['Trial',num2str(IterationNoLast10)];
p1=plot(PixelCountLast10((TrialLast10):((TrialLast10)+449)),'DisplayName',txtLast10),'Color',ColMap(TrialLast10,:)); %I get error here
hold on;
Max_ylimLast10= max(PixelCountLast10)+150;
Min_ylimLast10=min(PixelCountLast10)-150;
hold on;
end
%...some code..-->
댓글 수: 0
답변 (1개)
Mehmed Saad
2020년 6월 25일
편집: Mehmed Saad
2020년 6월 25일
Try the following strategy
cmp=distinguishable_colors(20);
f=figure;
ax = gca(f);ax.ColorOrder = cmp;
hold on;
A = rand(100,20)+(1:20);
for ii =1:20
plot(A(:,ii))
end
hold off
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Orange에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!