how to plot 40 different colors in matlab graph

i am plotting 200 users in a cells.
Among 200 users first five users should be in one color,next five in other color,and so on till i have plotted all 200users.
So totally i need 40 different colors to differentiate them.
I mentioned 8 colors using( 'm','g','y','b','r','c','w','k').How can I represent the rest of 32 colors in graph.
Could anyone please help me on this.

 Respuesta aceptada

Image Analyst
Image Analyst el 14 de En. de 2021
jaah:
Try this:
% x and y are your data, in rows of a matrix.
numDataSets = size(x, 1); % For example 200
plotColors = jet(numDataSets/5); % 40 different colors.
for row = 1 : numDataSets
% Extract this particular set of (x,y) coordinates from the whole data set.
thisX = x(row, :);
thisY = y(row, :);
% Now plot just this one.
thisIndex = ceil(row/5);
thisColor = plotColors(thisIndex, :);
plot(thisX, thisY, '-', 'Color', thisColor, 'LineWidth', 2);
hold on; % Leave plots up so we'll see all of them at the end.
end
grid on;
xlabel('x', 'FontSize', 20);
ylabel('y', 'FontSize', 20);
title('Demo by Image Analyst', 'FontSize', 20);

Más respuestas (1)

Rakhi Agarwal
Rakhi Agarwal el 22 de Feb. de 2019

0 votos

Colors in Matlab plot that you are using are basically RGB triplets. For example
blue b [0,0,1]
black k [0,0,0]
red r [1,0,0]
green g [0,1,0]
white w [1,1,1] etc.
You can define more colors using RGB triplets. You can specify colors using a vector. Usually RGB colors have values from 0 to 255. You can use those numbers and divide the vector by 255 to use within MATLAB. You can put in the RGB triplet (as a vector) directly into the plot command.
Read more about it here:

12 comentarios

jaah navi
jaah navi el 22 de Feb. de 2019
ok.Could you please help me how to represent purple color by a string.
Sure. Use this:
plot(data1, 'Color',[.6 .5 .7])
It'll make a nice purple color.
jaah navi
jaah navi el 22 de Feb. de 2019
I used the following command to plot the grpah
cluster_colors = ['m','g','y','b','r','c','k','[.6 .5 .7]'];% for different colors
when i run the code it gives error stating Specified string is an invalid color value.
I know its due to the representation [.6 .5 .7] along with the other string.
Could you help me to how to represent purple color along with the remaining colors in the command to get executed without any error.
Don't put it in ' '. And define other colors also as RGB. Use this:
cluster_colors = [[1,0,1]; [0,1,0]; [1,1,0]; [0,0,1]; [1,0,0]; [0,1,1]; [0,0,0]; [.6 .5 .7]];% for different colors
Now just use this to plot:
plot(data1, 'Color', cluster_colors(5,:))
Replace 5 with whichever color you want from cluster_colors array.
jaah navi
jaah navi el 22 de Feb. de 2019
when i used the folowing command
cluster_colors = [[1,0,1]; [0,1,0]; [1,1,0]; [0,0,1]; [1,0,0]; [0,1,1]; [0,0,0]; [.6 .5 .7]];
Its showing error stating Color value must be a 3 element vector.
Rakhi Agarwal
Rakhi Agarwal el 22 de Feb. de 2019
Works fine for me. Can you show the created cluster array from your workspace?
Stephen23
Stephen23 el 22 de Feb. de 2019
Editada: Stephen23 el 22 de Feb. de 2019
@jaar navi: this worked without error when I tried it:
>> M = [1,0,1;0,1,0;1,1,0;0,0,1;1,0,0;0,1,1;0,0,0;0.6,0.5,0.7];
>> plot([0,1],[1,0],'-*','Color',M(8,:))
While that page is okay, it totally fails to mention how to change the ColorOrder property, which would actually be quite useful for you.
jaah navi
jaah navi el 22 de Feb. de 2019
data displayed in workspace
1 0 1
0 1 0
1 1 0
0 0 1
1 0 0
0 1 1
0 0 0
0.600000000000000 0.500000000000000 0.700000000000000
This looks fine. It should work. It's working fine for me.
cluster_colors = [[1,0,1]; [0,1,0]; [1,1,0]; [0,0,1]; [1,0,0]; [0,1,1]; [0,0,0]; [.6 .5 .7]];% for different colors
plot(data1, 'Color', cluster_colors(5,:))
Try again. Don't forget to clear variables to avoid error due to previously stored value at the beginning of the code.
clear variables
Thomas Dixon
Thomas Dixon el 13 de En. de 2021
I fail to see how we plot multiple different colours from this? I am looking for something where I can plot some number of lines with different colours on the same plot by hopefully providing a matrix of (nx3) or (3xn) numbers where the 3 is the rgb triplet and n is the number of lines. Is this possible?
Thomas Dixon
Thomas Dixon el 13 de En. de 2021
I am adding this so i can follow activity
Thomas, yes, for example
% x and y are your data, in rows of a matrix.
numDataSets = size(x, 1);
plotColors = jet(numDataSets);
for row = 1 : numDataSets
% Extract this particular set of (x,y) coordinates from the whole data set.
thisX = x(row, :);
thisY = y(row, :);
% Now plot just this one.
plot(thisX, thisY, '-', 'Color', plotColors(row, :), 'LineWidth', 2);
hold on; % Leave plots up so we'll see all of them at the end.
end
grid on;
xlabel('x', 'FontSize', 20);
ylabel('y', 'FontSize', 20);
title('Demo by Image Analyst', 'FontSize', 20);

Iniciar sesión para comentar.

Categorías

Más información sobre Networks en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

el 22 de Feb. de 2019

Comentada:

el 1 de Feb. de 2021

Community Treasure Hunt

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

Start Hunting!

Translated by