How can I plot 18 lines in different colors on a single plot?
이전 댓글 표시
Hi everyone!
I have to plot 18 different functions of time, all in one single figure. How can i assign 18 different colors? (i work with matlab 2014)
Thanks.
채택된 답변
추가 답변 (2개)
Bjorn Gustavsson
2023년 1월 10일
For that type of tasks I have had good use of the cmlines-function in the colormap-and-colorbar-utilities toolbox on the file exchange. With that it is as simple as:
ph = plot(randn(18,18));
colormap(turbo)
cmlines(ph(1:12))
colormap(copper)
cmlines(ph(13:18))
(unasked for advice: sometimes my plots become more legible if I also use linewith and linestyle to differentiate between lines)
HTH
the cyclist
2023년 1월 10일
편집: the cyclist
2023년 1월 10일
0 개 추천
If your version of MATLAB is 2019b or later, I suggest the colororder function. (I see that you mention an older version, so this may be more for other folks who come across this question.)
And for that many colors, I would recommend using a utility like this one for defining maximally distinguishable colors (and/or using different plotting symbols and line styles.)
댓글 수: 1
Bjorn Gustavsson
2023년 1월 10일
Hopefully there are some more "natural" ordering and/or grouping of the function to plot, and then it might be way better to one distinct colormap per group of curves to guide the viewer.
카테고리
도움말 센터 및 File Exchange에서 2-D and 3-D Plots에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

