Plotting multiple lines with difference specific colours via plot function

조회 수: 4 (최근 30일)
Kaelan Wade
Kaelan Wade 2017년 5월 1일
편집: Stephen23 2017년 5월 1일
Is there any way to use the plot function to plot multiple lines, each having a specific colour?
e.g plot(x1,y1,'-','color',[0 0 1],x2,y2, '-', 'color',[1 0.4 0.6])
This doesn't work, but is there any way of properly doing this?

답변 (2개)

Kaelan Wade
Kaelan Wade 2017년 5월 1일
You can't combine everything into one single plot function.
What you can do is combine different plots via using hold on/off
E.g plot(x1,y1,'-','color',[0 0 1]) hold on plot(x2,y2, '-', 'color', [1 0.4 0.6]) hold off
  댓글 수: 1
Stephen23
Stephen23 2017년 5월 1일
편집: Stephen23 2017년 5월 1일
"You can't combine everything into one single plot function." Really?
See my answer for the correct way of doing this without requiring multiple plot calls.

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


Stephen23
Stephen23 2017년 5월 1일
편집: Stephen23 2017년 5월 1일
You just need to set the line ColorOrder property of the axes, then you just need one plot call:
>> map = [0,0,1;1,0.4,0.6];
>> axes('ColorOrder',map,'NextPlot','replacechildren')
>> plot([0,1],[1,2],'-',[0,1],[2,1],'*-')

카테고리

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

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by