Setting colors for plot function

15 visualizaciones (últimos 30 días)
Julián Francisco
Julián Francisco el 3 de Nov. de 2011
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});

Respuesta aceptada

Image Analyst
Image Analyst el 3 de Nov. de 2011
  1 comentario
Julián Francisco
Julián Francisco el 3 de Nov. de 2011
@Image Analyst: Thank you so much for your answer.

Iniciar sesión para comentar.

Más respuestas (1)

Walter Roberson
Walter Roberson el 3 de Nov. de 2011
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 comentarios
Julián Francisco
Julián Francisco el 5 de Nov. de 2011
@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 el 5 de Nov. de 2011
That sounds unlikely to be the case, but I do not have access to MATLAB this evening to test it out.

Iniciar sesión para comentar.

Categorías

Más información sobre Migrate GUIDE Apps en Help Center y File Exchange.

Etiquetas

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by