Setting colors for plot function

조회 수: 13 (최근 30일)
Julián Francisco
Julián Francisco 2011년 11월 3일
I would like to be able to choose the colors for a multiline plot but I can not get it. This is my code
colors = {'b','r','g'};
T = [0 1 2]';
column = [2 3];
count = magic(3);
SelecY = count(:,column),
plot(T,SelecY,'Color',colors{column});

채택된 답변

Image Analyst
Image Analyst 2011년 11월 3일
  댓글 수: 1
Julián Francisco
Julián Francisco 2011년 11월 3일
@Image Analyst: Thank you so much for your answer.

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

추가 답변 (1개)

Walter Roberson
Walter Roberson 2011년 11월 3일
You cannot specify different colors in multi-column (multi-line) plot() calls.
You can record the handles and set the colors individually:
h = plot(T,SelecY);
for K = 1 : length(h)
set(h,'Color', colors{column(K)});
end
Another approach is use the axes ColorOrder property. See here. (Note: you need RGB color specifications for that approach.)
  댓글 수: 2
Julián Francisco
Julián Francisco 2011년 11월 5일
@Walter Roberson: Thank you very much for your answer. However, your response is not be able to select different colors for the plot (both lines of the code appear with the same one).
Walter Roberson
Walter Roberson 2011년 11월 5일
That sounds unlikely to be the case, but I do not have access to MATLAB this evening to test it out.

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

카테고리

Help CenterFile Exchange에서 Migrate GUIDE Apps에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by