Setting colors for plot function

27 次查看(过去 30 天)
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 个)

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 中查找有关 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!

Translated by