Defining scatter plot with different 'markers' & 'colors'

3 vues (au cours des 30 derniers jours)
kenneth lee
kenneth lee le 23 Fév 2020
Commenté : Rik le 13 Mar 2020
Hi i am plotting a 3D scatter plot however i have to mark all 12 different classes on the 4th colomun in the attached file with 12 different markers and colors. Is there a way to randomize the 12 colors and markers all do i have to define them one by one? l only know how to do up till the 3d plot. Thanks in advance! :)
function plot3Ddata(x,y,z)
test = xlsread('HQ3.xlsx', 'A2:C223');
x=test(:,1);
y=test(:,2);
z=test(:,3);
scatter3(x,y,z);
end
the above code is my code for now...

Réponse acceptée

Rik
Rik le 23 Fév 2020
This should be close to what you need:
test = xlsread('HQ3.xlsx', 'A2:D223');
x=test(:,1);
y=test(:,2);
z=test(:,3);
groups=test(:,4);
figure(1),clf(1)
for g=1:max(groups)
L=groups==g;
scatter3(x(L),y(L),z(L),...
'DisplayName',sprintf('group %d',g));
hold on
end
hold off
legend
  3 commentaires
kenneth lee
kenneth lee le 13 Mar 2020
Hi so sorry for the late response, but is there a possibility to make all of them with different shapes and colors as i wan to distinctively reseperate them for better visualisation. Thanks alot for the follow up, really appreciate it! :)
Rik
Rik le 13 Mar 2020
If you don't want circles you can use plot3 instead of scatter3. Then you can set the LineSpec to whatever spec you like.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Scatter Plots dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by