How can I produce different colours for different clusters?

Hi,
I have the following dataset --> three columns (x,y, class of the data point(0,1,2,3 or 4)).
(-9.69171, -8.86384, 0)
(-9.55902, -8.10946, 0)
(-1.73544, -7.12043, 1)
(-1.77755, -6.39318, 1)
(-3.79288, -5.00445, 2)
(-3.36182, -6.39692, 2)
(-1.46405, -1.70081, 3)
(-0.413965, -2.22041, 3)
(-9.59192, -8.78982, 4)
(-9.72115, -8.37142, 4)
(This is just a sample dataset)
How can I plot that dataset where each data point has the same colour of its label. (The data is labelled in four groups).
Thank you

 Respuesta aceptada

pointsize = 30;
scatter(x(:), y(:), pointsize, group_number+1);
colormap(jet(5))

6 comentarios

Abdulatif Alabdulatif
Abdulatif Alabdulatif el 16 de Mayo de 2016
Editada: Abdulatif Alabdulatif el 16 de Mayo de 2016
I did not catch you answer because I am not very familiar with Matlab.
The matrix name: sample
size: 217 rows and 3 columns (x,y,class value)
How can I implement your commands, do I need to write it as a function or just paste it in a command line one by one.
Take into consideration that I want all points in the same plot with different colour for each class.
Thanks
pointsize = 30;
scatter(sample(:,1), sample(:,2), pointsize, sample(:,3)+1);
colormap(jet(5))
The sample(:,3)+1 will give the colormap index to use -- so use color #1 for group 0, color #2 for group 1, and so on. And then the colormap(jet(5)) tells it to use 5 different colors in the colormap, so each of those 5 groups will get colored distinctly.
Abdulatif Alabdulatif
Abdulatif Alabdulatif el 16 de Mayo de 2016
Editada: Abdulatif Alabdulatif el 16 de Mayo de 2016
Perfect!
One more question: Is it possible to use different symbols (+, * , -) for each class?
Thanks a lot for your support
You would need to use separate scatter() calls for each class. Any one call to scatter() can only use one symbol.
Abdulatif Alabdulatif
Abdulatif Alabdulatif el 17 de Mayo de 2016
Editada: Abdulatif Alabdulatif el 17 de Mayo de 2016
Great!
1- How can I plot from 1 to 100 in separate scatter with a specific symbol?
Thanks
symbols = {'*', '+', '.', 'v', 'p'};
for idx = 1 : length(symbols)
mask = group_number == idx;
scatter(x(mask), y(mask), pointsize, 'Marker', symbols{idx});
hold on
end

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by