Filter löschen
Filter löschen

how to plot 40 different colors in matlab graph

221 Ansichten (letzte 30 Tage)
jaah navi
jaah navi am 22 Feb. 2019
Kommentiert: Thomas Dixon am 1 Feb. 2021
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.

Akzeptierte Antwort

Image Analyst
Image Analyst am 14 Jan. 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);

Weitere Antworten (1)

Rakhi Agarwal
Rakhi Agarwal am 22 Feb. 2019
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 Kommentare
Thomas Dixon
Thomas Dixon am 13 Jan. 2021
I am adding this so i can follow activity
Image Analyst
Image Analyst am 14 Jan. 2021
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);

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu 2-D and 3-D Plots finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by