![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/509032/image.png)
Coloring of different index/numbered points
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Rubel Ahmed
le 4 Fév 2021
Commenté : Rubel Ahmed
le 4 Fév 2021
Hi all,
I have several points say 100 points. Each points have unique index/number from 1 to 100. I want to see 1 to 20 index point as blue color, 21-40 index point is red, 41-60 is green,61-80 is yellow ,and 81-100 is purple. How can I do this? Thanks in advance.
0 commentaires
Réponse acceptée
Image Analyst
le 4 Fév 2021
try this:
markerSize = 50;
x = rand(100, 1);
y = rand(100, 1);
plot(x(1:20), y(1:20), 'b.', 'MarkerSize', markerSize);
hold on;
plot(x(21:40), y(21:40), 'r.', 'MarkerSize', markerSize);
plot(x(41:60), y(41:60), 'g.', 'MarkerSize', markerSize);
plot(x(61:80), y(61:80), 'y.', 'MarkerSize', markerSize);
purple = [0.6, 0, 0.6];
plot(x(81:100), y(81:100), '.', 'Color', purple, 'MarkerSize', markerSize);
grid on;
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/509032/image.png)
Plus de réponses (1)
Peter Bonavita
le 4 Fév 2021
You can use hold on to plot multiple sets of points on the same figure, and customize the plot of each set.
Here's an example. Check out the linespec section of the plot documentation for more info about changing the color!
x = rand(100,1);
figure; hold on; % hold on lets me plot multiple sets of points on same figure
plot((1:20),x(1:20),'bo'); %blue, circle
plot((21:40),x(21:40),'ro'); %red circle
plot((41:60),x(41:60),'go') %green circle
plot((61:80),x(61:80),'yo') %yellow circle
plot((81:100),x(81:100),'mo'); %magenta circle
Voir également
Catégories
En savoir plus sur Line Plots dans Help Center et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!