Plotting 20-100 line with different distinguishable colors and shades on the same figure using a for loop
14 次查看(过去 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.![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/321763/image.jpeg)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/321763/image.jpeg)
%.<---...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 中查找有关 Blue 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!